• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Javamail: Problem sending attachments  RSS feed

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 21742
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Fire me boy! Cool, soothing, shameless self promotion:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!