IOException while sending the mail with attachment

Hi All,

Please help me regading my problem,

Here is my code to send message with attachment.

Without attachment it sent mail successfully.

In my project i used servlet and the sending code is as part of the applet.

Here the parameter file is getting from the server :

\Spaceco\SpaceCoReports\043628-05-23-2007(06-54-39PM).pdf

Spaceco is my project name.

I got the exception while tramsport the mssage.

Transport.send(msg);

publicvoid postMail( String smtpHost, String recipients[], String subject,

String message , File file, String from)throws MessagingException

{

boolean debug =false;

//Set the host smtp address

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[i] =new InternetAddress(recipients[i]);

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.toString())).getName());

multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);

}

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

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

}

Here is my exception :

javax.mail.MessagingException: IOExceptionwhile 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:448)

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

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

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

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: \Spaceco\SpaceCoReports\043628-05-23-2007(06-54-39PM).pdf (The system cannot find the path specified)

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

I really struggled with this issue,

Please can any one guide me!

Thanks,

Kiran

[7012 byte] By [p.v.k.ka] at [2007-11-27 5:15:12]
# 1
Caused by: java.io.FileNotFoundException: \Spaceco\SpaceCoReports\043628-05-23-2007(06-54-39PM).pdf (The system cannot find the path specified)Hint hint. Is that a share? Not sure how Java deals with those.
CeciNEstPasUnProgrammeura at 2007-7-12 10:37:21 > top of Java-index,Java Essentials,Java Programming...
# 2

> Caused by: java.io.FileNotFoundException:

> \Spaceco\SpaceCoReports\043628-05-23-2007(06-54-39PM).

> pdf (The system cannot find the path specified)

>

>

> Hint hint. Is that a share? Not sure how Java deals

> with those.

here we didnot get any exception.

DataSource source = new FileDataSource(file);

[/cede]

Is the attached file getting while the following code executed?

[code]

tranport.send(msg)

Thanks,

p.v.k.ka at 2007-7-12 10:37:21 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi ,help me
p.v.k.ka at 2007-7-12 10:37:21 > top of Java-index,Java Essentials,Java Programming...
# 4
The location has to be eitherD:/bla bla bla or if share folder then//share/shre1/..... can u tell where is the file? on ur machine or share
New_Kida at 2007-7-12 10:37:21 > top of Java-index,Java Essentials,Java Programming...