cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Attachments via email using Java mail API.

Former Member
0 Kudos

Hi,

I am developing an application which uses javamail API to send a mail along with an attachment to the specified user.

I am able to successfully send the text message via mail.

But sending mails with attachments is not working for me.

I have checked all the content in SDN and google, but none of them are clear enough to solve my problem.

I am using the below code for attachment

DataSource fds = new FileDataSource("fileName"); //The path to the fie to be attached

mimeBodyPart_Attachment.setDataHandler(new DataHandler(fds));

mimeBodyPart_Attachment.setFileName("fds.getName()");

My Question is

What exactly should be the fileName here?

can it be just a path to any of the documents in my local desktop say for example, "D:\Documents and Settings\Arrivals.xls"?

or should I first store the file to be attached in the server and then give the path of the document in the server as fileName?

I tried both the ways, I am getting FileNotFoundException (The device is not ready).

Has anyone worked on attachments in java mail or faced this issue before?

Kindly let me know.

Regards,

Shilpa B.V

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member185086
Active Contributor
0 Kudos

Hi

Please follow this [thread|http://www.jguru.com/faq/view.jsp?EID=30251] .

Best Regards

Satish Kumar

Former Member
0 Kudos

Check the bottom of the thread.

It should be something like "c:
a.txt"

Thanks

Avik

Former Member
0 Kudos

Shilpa,

Refer to [this|http://www.jguru.com/faq/view.jsp?EID=30251] link. It mentions that you have to use the absolute file path. I would suggest that you try using a simpler path where the path does not contain spaces.

Thanks,

GLM