This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes javamail API question: How to send content type in message body when using multiparts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "javamail API question: How to send content type in message body when using multiparts" Watch "javamail API question: How to send content type in message body when using multiparts" New topic
Author

javamail API question: How to send content type in message body when using multiparts

Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
Hello,

I am using JavaMail API in order to send message with attachment and it's working OK.
When using mail API without Multiparts you can use the msg.setContent() method to specify that the message bodt is of type "text/html" but that doesn't work when using Multiparts.
My question is: When using Multiparts, where can I specify that my body is of type "text/html". Here's my code:

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(MAIL));
msg.setRecipient(Message.RecipientType.TO, email);
msg.setSubject("My Subject");
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Hello");
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
Transport.send(msg);

Now, I would like to transfer the "Hello" text that I see in the body as html in order to be able to set html tags in it.
[ September 22, 2007: Message edited by: Roy Cohen ]
 
Have you checked out Aspose?
 
subject: javamail API question: How to send content type in message body when using multiparts
 
It's not a secret anymore!