• 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

How to get Attachment in Java Send email code?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I'm working on my project in Java to send emails from database with attachments. My code send emails plus all Body part but I'm not getting any attachments which are pdf format. I haven't work before with
javax.mail.api and I'm not familiar with all syntax that I need to fix my code. Here is the code that I use:



If anyone can tell me what I'm missing in my code please let me know.
 
Bartender
Posts: 2278
95
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this tutorial might help ?

http://www.tutorialspoint.com/javamail_api/javamail_api_send_email_with_attachment.htm

As I understand it correctly, you need to add body part to your message
 
Miki Draka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I followed tutorial but still something is wrong with my code. I still cannot get my .pdf file attached in email, in other hand .txt file are attached and worked fine.
Here is the code that I use now:

 
Sheriff
Posts: 21743
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Miki Draka wrote:


That last line is wrong. The multipart's content type is not "application/pdf". You should just call message.setContent(multipart);. The application/pdf should go on the messageBodyPart instead. The DataHandler will take care of that, provided that it can figure out the correct mime type for the source (based on its filename).
 
Miki Draka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Miki Draka wrote:


That last line is wrong. The multipart's content type is not "application/pdf". You should just call message.setContent(multipart);. The application/pdf should go on the messageBodyPart instead. The DataHandler will take care of that, provided that it can figure out the correct mime type for the source (based on its filename).



Miki wrote:
Thank you. That caused my code to crash.

 
Rob Spoor
Sheriff
Posts: 21743
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you mean my suggestion caused a "crash"? If so, please post the stack trace (because I assume that "crash" means exception).
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
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!