如何使用 Java 将 Outlook 电子邮件转换为 TIFF

在这篇简单的文章中,我们将按照设置环境的详细步骤学习如何使用 Java Outlook Email 转换为 TIFF。为了将 EML 转换为 TIFF 基于 Java 的 API 提供了一个简单的 API 接口,可以在 MS Windows、macOS 或 Linux 中任何支持 Java 的环境中使用。

使用 Java 将 Outlook 电子邮件转换为 TIFF 的步骤

  1. 设置环境以从存储库安装 Aspose.EmailAspose.Words JAR 文件
  2. 实例化MailMessage类对象加载源MSG或EML格式文件
  3. 将访问的电子邮件 (EML/MSG) 文件保存为中间 MHTML 格式流
  4. 通过实例化 Document 类对象加载中间格式 MHTML 流
  5. 使用 save 方法将加载的 EML 文件保存到磁盘上的 TIFF 文件

通过遵循 Java Email to TIFF 中的上述步骤,可以开发渲染应用程序,由此过程将通过使用 MailMessage 类的实例从磁盘访问源 MSG 或 EML 文件来开始。在后续步骤中,该文件被保存为内存流中的中间 MHTML 文件,然后使用 Document 类对象加载该文件。最后,加载的 MHTML 将使用 save 方法在磁盘上呈现为 TIFF 文件。

使用 Java 将 Outlook 电子邮件转换为 TIFF 的代码

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);
}
}

将 EML 转换为 TIFF Java,请遵循以上示例中基于简单 API 接口和指南的步骤。这是一个两步过程,其中第一步涉及加载 EML 或 MSG 文件并将其渲染到内存流中的中间 MHTML 文件。第二步涉及将 MHTML 及其渲染加载到磁盘上的 TIFF 文件中。

在这个简短的主题中,我们见证了如何使用基于 Java* 的 API *将 Outlook 电子邮件转换为 TIFF。如果您有兴趣了解如何在没有 MS Outlook 的情况下打开 MSG 文件,请参阅 如何用Java打开MSG文件 上的文章。

 简体中文