在这个简单的教程中,我们将学习如何使用 C#** 将 EML 转换为 MSG 以及设置环境的详细步骤。为了将 EML 转换为 MSG,可以使用基于 C# 的 API,您可以在任何常用操作系统(如 Windows、macOS 或 Linux)中使用此示例。
使用 C# 将 EML 转换为 MSG 的步骤
- 从 Visual Studio 中的 NuGet 包管理器工具安装 Aspose.Email 库
- 在项目中导入 Aspose.Email 命名空间
- 设置 EmlLoadOptions 以加载 EML 文件
- 初始化 MailMessage 类对象以加载源 EML 文件
- 使用 Save 方法将 EML 转换为 MSG 文件
通过使用上述C# EML to MSG 转换应用程序的步骤被开发出来。通过使用 MailMessage 类对象从磁盘加载源 EML 文件来启动该过程。然后使用 SaveOptions.DefaultMsg 和 SaveOptions.DefaultMsgUnicode 枚举器在 Save 方法中将加载的 EML 文件作为 MSG 文件保存在磁盘上。
在 C# 中将 EML 转换为 MSG 的代码
using System; | |
using Aspose.Email; | |
namespace KbEmail | |
{ | |
public class EmlToMsgConverter | |
{ | |
public static void ConvertEmlToMsg() | |
{ | |
// Initialize a license to convert EML to MSG | |
License licenseEmail = new License(); | |
licenseEmail.SetLicense("Aspose.Total.lic"); | |
EmlLoadOptions emlLoadOptions = new EmlLoadOptions(); | |
emlLoadOptions.PreserveTnefAttachments = true; | |
emlLoadOptions.PreserveEmbeddedMessageFormat = true; | |
using (MailMessage message = MailMessage.Load("TestEml.eml", emlLoadOptions)) | |
{ | |
// Convert EML to MSG | |
message.Save("output.msg", SaveOptions.DefaultMsg); | |
} | |
} | |
} | |
} |
上面 C# 中的示例借助简单的 API 调用和明确定义的步骤将 EML 转换为磁盘上的 MSG 文件。您可以在加载 EML 文件之前设置不同的 EmlLoadOptions,包括 PreserveTnefAttachments 和 PreserveEmbeddedMessageFormat。您还可以使用上面的示例通过使用 EmlLoadOptions 类的默认构造函数使用默认选项加载 EML 文件。
本文探讨了如何将 EML 转换为基于 MSG C# 的 API。如果您正在寻找如何在 C# 中将 EML 转换为 PDF,请参阅 如何使用 C# 将 Outlook 电子邮件转换为 PDF 上的文章。