个人中心

联系我们

搜索
搜索 登录 免费注册
界面美化
业务优化
开发工具
图像管理
文档管理
Parasoft

新闻资讯

关注工具软件产品最新动态,了解软件开发行业新趋势。

Aspose 使用教程:适用于 C# 开发人员的电子邮件转换软件 - 将 EML 转换为 PNG

原创
软件开发
来源:Aspose
Aspose
C#
格式转换
email
API
图像处理
.net
2024-04-16
Aspose
C#
格式转换
email
API
图像处理
.net


本文将帮助 C# 开发人员以编程方式将 EML 或 MSG 转换为其他流行的文件格式。Aspose.Email for .NET 提供了将 EML 无缝转换为 PNG 的类和方法以及在线电子邮件转换工具。如果不安装第三方软件,就无法打开 EML/MSG 文件。因此,将 EML/MSG 转换为 PNG 和 JPG 等图像文件格式可以让你轻松查看这些文件。因此,在本指南中,我们将通过代码片段用 C# 制作一个电子邮件转换软件。在开始之前,请确保您有 EML 和 MSG 源文件来实现该功能。


本文将介绍以下几点:


  • 电子邮件 API 集成与安装

  • 用 C# 将 EML 转换为 PNG

  • 以编程方式将 MSG 转换为 PNG

  • 免费电子邮件转换器 - 在线演示


电子邮件 API 集成与安装

要安装此企业级 .NET 库,请在 NuGet 包管理器中运行以下命令或在此处下载 DLL 文件。

Install-Package Aspose.Email


除了 Aspose.Email for .NET,您还需要安装 Aspose.Words for .NET API。

Install-Package Aspose.Words


Aspose.Email for .NET为开发人员提供了完整的安装指南。此外,安装只需几秒钟,您就可以开始使用 API 将 EML 转换为 PNG 或将 MSG 转换为 PNG。



用 C# 将 EML 转换为 PNG

现在,我们可以编写一个代码示例,用 C# 编程构建一个电子邮件转换工具。


以下步骤展示了如何构建一个电子邮件转换软件,将 EML 转换为 PNG:


  1. 创建一个 EmlLoadOptions 类对象,用于从 EML 格式加载 MailMessage。

  2. 设置 RemoveSignature 属性的值,以指示是否在加载时移除签名。

  3. 调用 MailMessage 类的 Load 方法加载 EML 源文件。

  4. 设置邮件的敏感度。

  5. 设置邮件的优先级。

  6. 实例化 MemoryStream 类的一个实例。

  7. 将 EML 转换为 MHTML,并通过调用 Save 方法保存到流中。

  8. 调用 Position 属性并设置流中的当前位置。

  9. 使用 MHTML 流初始化 Document 类的实例。

  10. 调用 Save 方法将文档保存为 PNG 图像。

以下代码片段用 C# 将 EML 转换为 PNG。

using Aspose.Email;
using Aspose.Words;
namespace Aspose.Email
{
    class EMLtoPNG
    {
        // Email conversion software for C# Developers - EML to PNG
        static void Main(string[] args)
        {
            string dataDir = "/sample-files/";
            // Create an object of the EmlLoadOptions class that will be used to load MailMessage from EML format.  
            EmlLoadOptions emlLoadOptions = new EmlLoadOptions();
            // Set a value of RemoveSignature property to indicate whether signature will be removed while loading. 
            emlLoadOptions.RemoveSignature = false;
            // Invoke the Load method of the MailMessage class to load the source eml file. 
            MailMessage msg = MailMessage.Load(dataDir + "sample.eml", emlLoadOptions);
            // Set the Sensitivity of the message. 
            msg.Sensitivity = MailSensitivity.Normal;
            // Set the Priority of the message. 
            msg.Priority = MailPriority.High;
            // Instantiate an instance of the MemoryStream class. 
            MemoryStream msgStream = new MemoryStream();
            // Convert EML to MHTML and save to stream by calling the Save method. 
            msg.Save(msgStream, SaveOptions.DefaultMhtml);
            // Invoke the Position property and set the current position within the stream. 
            msgStream.Position = 0;
            // Initialize an instance of the Document class with the MHTML stream. 
            Document msgDocument = new Document(msgStream);
            // Save the document as PNG image by calling the Save method. 
            msgDocument.Save(dataDir + "Outlook-Aspose_out.png", SaveFormat.Png);
        }
    }
}


您可以在下图中看到输出结果:



通过编程将 MSG 转换为 PNG

同样,您也可以通过对上述代码片段进行以下修改,将 MSG 转换为 PNG:


  1. 创建一个 MsgLoadOptions 类对象,并将其作为参数传递给 MailMessage 类的 Load 方法,以加载 MSG 源文件。

以下代码示例演示了如何在 .NET 中将 MSG 转换为 PNG:

using Aspose.Email;
using Aspose.Words;
namespace Aspose.Email
{
    class MSGtoPNG
    {
        // Email conversion software for C# Developers - MSG to PNG
        static void Main(string[] args)
        {
            string dataDir = "/sample-files/";
            // Create an object of the MsgLoadOptions class that will be used to load MailMessage from MSG format.  
            MsgLoadOptions msgLoadOptions = new MsgLoadOptions();
            // Set a value of RemoveSignature property to indicate whether signature will be removed while loading. 
            msgLoadOptions.RemoveSignature = false; 
            // Invoke the Load method of the MailMessage class to load the source MSG file. 
            MailMessage msg = MailMessage.Load(dataDir + "sample.msg", msgLoadOptions);
            // Set the Sensitivity of the message. 
            msg.Sensitivity = MailSensitivity.Normal;
            // Set the Priority of the message. 
            msg.Priority = MailPriority.High;
            // Instantiate an instance of the MemoryStream class. 
            MemoryStream msgStream = new MemoryStream();
            // Convert MSG to MHTML and save to stream by calling the Save method. 
            msg.Save(msgStream, SaveOptions.DefaultMhtml);
            // Invoke the Position property and set the current position within the stream. 
            msgStream.Position = 0;
            // Initialize an instance of the Document class with the MHTML stream. 
            Document msgDocument = new Document(msgStream);
            // Save the document as PNG image by calling the Save method. 
            msgDocument.Save(dataDir + "Outlook-Aspose_out.png", SaveFormat.Png);
        }
    }
}


免费电子邮件转换器 - 在线演示

我们已经了解了如何为 C# 开发人员开发电子邮件转换软件。这是一款将 EML 在线转换为 PNG 的在线工具。它由 Aspose.Email 提供支持。此外,这款电子邮件转换工具基于网络,界面友好,你还可以在手机上使用这款电子邮件转换器。最重要的是,它是免费的,使用前无需订阅。



电子邮件转换软件 - 获取免费许可证

您可以获得免费的临时许可证,试用 Aspose.Email for .NET,不受评估限制。


结束语

希望这篇文章对您有所帮助,我们就此结束本文。我们已经介绍了如何使用 Aspose.Email for .NET 在 C# 中构建电子邮件转换软件。此外,我们还探讨了将 EML 在线转换为 PNG 的在线电子邮件转换工具。此外,您还可以查阅文档和 API 参考资料,了解其全部功能。


常见问题 - FAQ

如何将 EML 文件转换为图像?

您可以使用 Aspose.Email 将 EML 转换为 PNG。该库支持多种编程语言。

如何转换 MSG 文件?

试试我们的在线免费电子邮件转换器,将 EML/MSG 转换为其他常用文件格式。



联系我们

周一至周日 8:00-23:00

免费热线

023-62585653

张经理:13082556879

罗经理:17558866126

许经理:13057566525

开发外包

ERP-一体化

小程序

企业微信客服

版权所有:重庆庚乾信息科技有限公司 ©2025 Gengqian Information Technology Co., Ltd. 渝ICP备2022008063号-2 渝公网安备50010702505508

版权所有:重庆庚乾信息科技有限公司

©2025 Gengqian Information Technology Co., Ltd. 渝ICP备2022008063号-2 渝公网安备50010702505508