IOException

Hi All,

Please can any one help me!

Here i sending mail though the applet application:

I get the IOException at last line (1)

Here is my code part :

Properties props = new Properties();

props.put("mail.smtp.host", smtpHost);

props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();

Session session = Session.getDefaultInstance(props, auth);

session.setDebug(debug);

// create a message

Message msg = new MimeMessage(session);

// set the from and to address

InternetAddress addressFrom = new InternetAddress(from);

msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];

for (int i = 0; i < recipients.length; i++)

addressTo = new InternetAddress(recipients);

msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type

msg.setSubject(subject);

msg.setSentDate(new Date());

if(!file.equals(""))

{

BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message

messageBodyPart.setText(message);

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

// Part two is attachment

messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(file);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName((new File(file)).getName());

multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);

}

else msg.setContent(message, "text/plain");

Transport.send(msg); // (1)

>

This code successflly sent mail through the frames.

Plase any one make the commnet regarding my issue.

Thanks,

Kiran

[1856 byte] By [p.v.k.ka] at [2007-11-27 5:08:05]
# 1
Can you post the exact error message? It helps to be precise.
Hippolytea at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 2
Can you please edit your post and add code tags to your code. It makes it much easier to read.
maple_shafta at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 3
can you tell me about code tags?
p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 4
> can you tell me about code tags?[url= http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url]
Hippolytea at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 5

Hi All,

Please can any one help me!

Here i sending mail though the applet application:

I get the IOException at last line (1)

Here is my code part :

Properties props = new Properties();

props.put("mail.smtp.host", smtpHost);

props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();

Session session = Session.getDefaultInstance(props, auth);

session.setDebug(debug);

// create a message

Message msg = new MimeMessage(session);

// set the from and to address

InternetAddress addressFrom = new InternetAddress(from);

msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];

for (int i = 0; i < recipients.length; i++)

addressTo = new InternetAddress(recipients);

msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type

msg.setSubject(subject);

msg.setSentDate(new Date());

if(!file.equals(""))

{

BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message

messageBodyPart.setText(message);

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

// Part two is attachment

messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(file);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName((new File(file)).getName());

multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);

}

else msg.setContent(message, "text/plain");

Transport.send(msg); // (1)

>

This code successflly sent mail through the frames.

Plase any one make the commnet regarding my issue.

Thanks,

Kiran

p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 6
Please help me!
p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 7
Can you post the exact error message? It helps to be precise.
Hippolytea at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 8

Here is my exception :

javax.mail.MessagingException: IOException while sending message

at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:595)

at javax.mail.Transport.send0(Transport.java:169)

at javax.mail.Transport.send(Transport.java:98)

at com.spaceco.JSpaceCoDynamics.onlineApp.sales.SendMail.postMail(SendMail.java:443)

at com.spaceco.JSpaceCoDynamics.onlineApp.sales.SendMail.okButtonActionPerformed(SendMail.java:368)

at com.spaceco.JSpaceCoDynamics.onlineApp.sales.SendMail.access$200(SendMail.java:57)

at com.spaceco.JSpaceCoDynamics.onlineApp.sales.SendMail$2.actionPerformed(SendMail.java:313)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Caused by: java.io.FileNotFoundException: http:\localhost:8080\Spaceco\SpaceCoReports\043628-05-22-2007(08-50-54 PM).pdf (The filename, directory name, or volume label syntax is incorrect)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(Unknown Source)

at javax.activation.FileDataSource.getInputStream(FileDataSource.java:80)

at javax.activation.DataHandler.writeTo(DataHandler.java:287)

at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1248)

at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:747)

at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:361)

at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:85)

at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)

at javax.activation.DataHandler.writeTo(DataHandler.java:295)

at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1248)

at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1673)

at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:555)

... 31 more

p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 9
acually my file located atfile : http://localhost:8080/Spaceco/SpaceCoReports/043628-05-22-2007(08-50-54 PM).pdfPlease help meThanks,Kiran
p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 10
Caused by: java.io.FileNotFoundException: http:\localhost:8080\Spaceco\SpaceCoReports\043628-05-22-2007(08-50-54 PM).pdf (The filename, directory name, or volume label syntax is incorrect)What does that tells you?
shittybytesa at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 11
I didn't change in path slashes.Can you tell me how to get the original path?Thanks,Kiran
p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 12

> I didn't change in path slashes.

> Can you tell me how to get the original path?

You have two problems here:

1.) You have a URL, not a File.

You're either going to have to point to it by filepath (C:/Program\ Files/blahblah) or download the file to a temporary location before you try to refer to it.

2.) Your URL has spaces in it.

Spaces in URLs need to be converted to "%20" in order to work.

kevjavaa at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 13

> You have two problems here:

> 1.) You have a URL, not a File.

> You're either going to have to point to it by

> filepath (C:/Program\ Files/blahblah) or download

> the file to a temporary location before you try to

> refer to it.

Can you suggest me how to get the file through the url?

or

how to dowm load the file , which located in the server?

Please help me, urgent!

> .) Your URL has spaces in it.

> Spaces in URLs need to be converted to "%20" in

> order to work.

Can you expalin this ?

Thanks,

Kiran

p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 14
Please help me!
p.v.k.ka at 2007-7-12 10:27:27 > top of Java-index,Java Essentials,Java Programming...
# 15
Um, you've got to give forum members more that 5 minutes to respond!
Hippolytea at 2007-7-21 21:19:46 > top of Java-index,Java Essentials,Java Programming...
# 16

> Can you suggest me how to get the file through

> the url?

Here's a nice example:

http://schmidt.devlib.org/java/file-download.html

However, your file is on localhost, so you can probably just map a path to it depending on where your server root is.

> Can you expalin this ?

http://localhost/filename with spaces

should become

http://localhost/filename%20with%20spaces

or perhaps

http://localhost/filename+with+spaces

You'll have to see what works.

kevjavaa at 2007-7-21 21:19:47 > top of Java-index,Java Essentials,Java Programming...
# 17
Given a java.net.URL object, you can use its method:InputStream openStream()method to open the URL, and then read from that stream and write to a local file.
Hippolytea at 2007-7-21 21:19:47 > top of Java-index,Java Essentials,Java Programming...
# 18

As the file you are attaching to the mail is not finding....

Probably ,first You can try to convert your URL(to the file) to path

Following links guide u through ...

1)http://www.exampledepot.com/egs/java.io/File2Uri.html

2)http://weblogs.java.net/blog/kohsuke/archive/2007/04/how_to_convert.html

Regards...

BalajiGaneshReddya at 2007-7-21 21:19:47 > top of Java-index,Java Essentials,Java Programming...
# 19
BalajiGaneshReddya at 2007-7-21 21:19:47 > top of Java-index,Java Essentials,Java Programming...
# 20
try yhis:Properties props = System.getProperties();
varun_koteshwara at 2007-7-21 21:19:47 > top of Java-index,Java Essentials,Java Programming...