How to Convert Outlook Email to TIFF using Java

In this simple article, we will learn how to convert Outlook Email to TIFF using Java by adhering to the detailed steps for setting up the environment. In order to convert an EML to TIFF Java based API providing a simple API interface can be used in any of the Java supported environments in MS Windows, macOS, or Linux.

Steps to Convert Outlook Email to TIFF using Java

  1. Set up the environment to install Aspose.Email and Aspose.Words JAR files from the repository
  2. Instantiate the MailMessage class object to load the source MSG or EML format file
  3. Save the accessed Email (EML/MSG) file to an intermediate MHTML format stream
  4. Load the intermediate format MHTML stream by instantiating the Document class object
  5. Save the loaded EML file to a TIFF file on the disk using the save method

By adhering to the above steps in Java Email to TIFF rendering application can be developed, whereby the process will commence by accessing the source MSG or EML file from the disk using an instance of the MailMessage class. In subsequent steps, the file is saved as an intermediate MHTML file inside a memory stream, which is then loaded by using a Document class object. Finally, the loaded MHTML will be rendered as a TIFF file on the disk using the save method.

Code to Convert Outlook Email to TIFF using Java

import com.aspose.email.MailMessage;
import com.aspose.words.Document;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class EmailToTiff {
public static void main2(String[] args) throws Exception { // Handle exception to convert EML to TIFF
String FilePath = "/Users/KnowledgeBase/TestData/";
// Set the product license to convert email to Tiff
com.aspose.email.License emailTiffLicense = new com.aspose.email.License();
emailTiffLicense.setLicense(FilePath + "Conholdate.Total.Product.Family.lic");
// Set the product license to convert EML to TIFF
com.aspose.words.License wordsTiffLicence = new com.aspose.words.License();
wordsTiffLicence.setLicense(FilePath + "Conholdate.Total.Product.Family.lic");
// Load the EML or an MSG file from the disk
MailMessage srcEmlMessage = MailMessage.load(FilePath + "Message.msg");
// Create the OutputStream object to hold intermediate MHTML
ByteArrayOutputStream intMhtmlStream = new ByteArrayOutputStream();
// Save the EML/MSG to an intermediate MHTML file
srcEmlMessage.save(intMhtmlStream, com.aspose.email.SaveOptions.getDefaultMhtml());
// Use the LoadOptions to set the LoadFormat to Mhtml
com.aspose.words.LoadOptions loadOpts = new com.aspose.words.LoadOptions();
loadOpts.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
// Create the Document class object to access the MTHML stream
Document mhtDocument = new Document(new ByteArrayInputStream(intMhtmlStream.toByteArray()), loadOpts);
// Save the loaded MHTML to a TIFF file using Java
mhtDocument.save(FilePath + "Saved-Aspose_out.tiff", com.aspose.words.SaveFormat.TIFF);
}
}

To convert EML to TIFF Java based simple API interface and guidelines steps have been followed in the above example. It is a two steps process, whereby the first step involves loading the EML or MSG file and its rendering to an intermediate MHTML file inside a memory stream. The second step involves, loading the MHTML and its rendering to a TIFF file on the disk.

In this brief topic, we witnessed how to convert Outlook Email to TIFF using Java based API. If you are interested in learning about opening an MSG file without MS Outlook, refer to the article on how to open MSG file in Java.

 English