• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 714
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aspose.Email API has made it very easy to convert an email message type to other formats. 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

- Download Aspose.Email for Java

- More Technical Tips by Aspose.Email for Java

Contact Information

Suite 119, 272 Victoria Avenue

Chatswood, NSW, 2067

Australia

Aspose - Your File Format Experts

sales@aspose.com


Phone: 888.277.6734

Fax: 866.810.9465

 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic