Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sending email attachment file from memory

 
Venkat Babu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some help on sending an email and attaching a file which is in memory.

I have this code getting the file from the file system.

MimeBodyPart mimePartAttach = new MimeBodyPart();
FileDataSource fileSource = new FileDataSource(fileName);
mimePartAttach.setDataHandler(new DataHandler(fileSource));
mimePartAttach.setFileName(fileName);
multiPart.addBodyPart(mimePartAttach);
mesg.setContent(multiPart);

But I am not sure how to send the attachment from memory

I have the content as byte[] and don't know how to convert into FileDataSource or DataHandler. Please help.


Thanks.
 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Venkat,
The Datahandler class has a constructor which takes Object and MIME type as input. Since you have the data in memory (probably as an object) use this constructor.
DataHandler(Object obj, String mimeType)

Hope this helps
[ March 11, 2008: Message edited by: Sivaraman Lakshmanan ]
 
Venkat Babu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sivaraman,

I am attaching a zip file, what is the MIME type I need to set?


Thanks,.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!