Important alert: (current site time 7/16/2013 7:22:46 AM EDT)
 

article

Convert Email Messages to MHTML, MSG & EML Using Aspose.Email Java API

Email
Submitted on: 1/30/2012 12:00:43 PM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.4), Java (JDK 1.5)
Views: 2743
 
     Steps to convert an existing Email Message to different formats.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				Aspose.Email API has made it very easy to convert an email message type to another format. To demonstrate the simplicity of this feature, we will load 3 different types of messages from the disk and save them back in other formats using Aspose.Email Java API.
Steps to convert an existing Email Message to different formats
Please perform the following sequence of steps for modifying an existing Email Message: 
•	Create an instance of MailMessage class.
•	Load the existing Email Message using the load() method exposed by MailMessage class and by specifying the correct MessageFormat.
•	Save the Message to disk by using the save() method exposed by MailMessage class and by specifying the correct MailMessageSaveType.
Load EML, save as MSG and MHTML
public static void main(String[] args)
{
// Base folder for reading and writing files
String strBaseFolder = "D:\\Data\\Aspose\\resources\\";
//Initialize and Load an existing EML file by specifying the MessageFormat
MailMessage msg = MailMessage.load(strBaseFolder + "AnEmail.eml", MessageFormat.getEml());
//Save the Email message to disk by specifying the MSG and MHT MailMessageSaveType
msg.save(strBaseFolder + "message.msg", MailMessageSaveType.getOutlookMessageFormat());
msg.save(strBaseFolder + "message.mhtml", MailMessageSaveType.getMHtmlFromat());
}
Load MSG, save as EML and MHTML
public static void main(String[] args)
{
// Base folder for reading and writing files
String strBaseFolder = "D:\\Data\\Aspose\\resources\\";
//Initialize and Load an existing MSG file by specifying the MessageFormat
MailMessage msg = MailMessage.load(strBaseFolder + "AnEmail.msg", MessageFormat.getMsg());
//Save the Email message to disk by specifying the EML and MHT MailMessageSaveType
msg.save(strBaseFolder + "message.eml", MailMessageSaveType.getEmlFormat());
msg.save(strBaseFolder + "message.mhtml", MailMessageSaveType.getMHtmlFromat());
}
Load MHTML, save as EML and MSG
public static void main(String[] args)
{
// Base folder for reading and writing files
String strBaseFolder = "D:\\Data\\Aspose\\resources\\";
//Initialize and Load an existing MHT file by specifying the MessageFormat
MailMessage msg = MailMessage.load(strBaseFolder + "AnEmail.mhtml", MessageFormat.getMht());
//Save the Email message to disk by specifying the EML and MSG MailMessageSaveType
msg.save(strBaseFolder + "message.eml", MailMessageSaveType.getEmlFormat());
msg.save(strBaseFolder + "message.msg", MailMessageSaveType.getOutlookMessageFormat());
} 
Overview: Aspose.Email for Java 
 
Aspose.Email for Java is a Non-Graphical Java component that enables Java applications to read and write MS Outlook MSG files from within a Java application without using MS Outlook. It enables developers to create new MSG file from scratch, update an existing MSG file, read Outlook MSG file & get its properties like subject, body, recipients in to, cc and bcc, adding or removing attachment, sender information & MAPI properties. Aspose.Email can be used with Web as well as Desktop Application.
More about Aspose.Email for Java 
- Homepage of Aspose.Email for Java: http://www.aspose.com/categories/java-components/aspose.email-for-java/default.aspx 
- Download Aspose.Email for Java: http://www.aspose.com/community/files/72/java-components/aspose.email-for-java/default.aspx 
 
- More Technical Tips by Aspose.Email for Java: http://docs.aspose.com/display/EmailJava/Programmers+Guide
 
Contact Information
Aspose Pty Ltd, Suite 163, 
79 Longueville Road
Lane Cove, NSW, 2066 
Australia 
http://www.aspose.com/
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.9465 


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.