wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes Javamail: Problem sending attachments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Javamail: Problem sending attachments" Watch "Javamail: Problem sending attachments" New topic
Author

Javamail: Problem sending attachments

Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
have the following code for sending emails


Although the email content is absolutely fine, the attachement is not gettig attached. The email comes without an attachment. Can someone please let me know how to attach a file to this email

Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
I updated my code a bit.

If I do the following, I get only the attachment without the HTML body (html body part is commented)


the following gives me HTML body wihtout attachment



I need both. HTML body as well as an attachment.

Can someone please let me know how to solve this problem.

Thank you
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

In your first example, you add all attachments, but then you overwrite them with the body.

You must use a MimeMultiPart, and create one body part for the HTML and one for each attachment. The file body part will work just as the one you have now; the HTML body part will be similar to how you set the HTML contents for your message.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anil Karamchandan
Ranch Hand

Joined: Sep 12, 2009
Posts: 47
A similar problem, I have my body part working, if I comment the code to the the filename, attachment. I have created MultiMimePart for body and for attachment but still get the error. Any suggestions for this please

Anil Karamchandan
Ranch Hand

Joined: Sep 12, 2009
Posts: 47
got the answer to my question, was setting the filename incorrectly, Its amazing how much you could learn by looking at the code of others...

truely amazing !

thanks !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javamail: Problem sending attachments
 
Similar Threads
Image as part of HTML email
Java mail problem
Attaching files using Java Mail API
Forwarding a mail in message/rfc822 Format
Problem in Java Mail using Servlet