发送保存在磁盘上的 eml 文件

Send eml files saved on disk(发送保存在磁盘上的 eml 文件)
本文介绍了发送保存在磁盘上的 eml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 eml 并使用 这里.我想知道如何发送这些 eml 文件?我尝试使用 SMTPClient 类的对象,但它将 MailMessage 对象作为其参数,我找不到使用这些保存的 eml 文件创建 MailMessage 类型对象的方法.

I am creating eml's and saving them to a directory using procedure mentioned over here. I want to know how to send these eml files? I tried using SMTPClient class's object but it takes MailMessage object as its parameter and I couldn't find and way to create an object of type MailMessage using these saved eml files.

推荐答案

正确加载 EML 文件并不像看起来那么容易.您可以在几天内编写一个适用于 95% 情况的实现.剩下的 5% 至少需要几个月的时间;-).我知道,因为我参与了开发.

Loading an EML file correctly is not as easy as it looks. You can write an implementation working in 95% cases within few days. Remaining 5% would take at least several months ;-). I know, becase I involved in developing one.

考虑以下困难:

  • unicode 电子邮件
  • 从右到左的语言
  • 更正由流行邮件客户端和服务器中众所周知的错误导致的格式错误的 EML 文件
  • 处理 S/MIME(加密和签名的电子邮件)
  • 正确处理几种编码附件的方法
  • 处理嵌入到 HTML 电子邮件中的内联图像和样式表
  • 确保它正确解析 MIME 折磨消息 来自 Mike Crispin(Mime 和 IMAP RFC 的合著者)
  • 确保格式错误的消息不会导致缓冲区溢出或其他应用程序崩溃
  • 处理分层消息(带有附加消息的消息)
  • 确保它能正确处理非常大的电子邮件
  • unicode emails
  • right-to-left languages
  • correcting malformed EML files caused by well known errors in popular mail clients and servers
  • dealing with S/MIME (encrypted and signed email messages)
  • dealing correctly with several methods of encoding attachments
  • dealing with inline images and stylesheets embedded into HTML emails
  • making sure that it parses correctly a MIME torture message from Mike Crispin (coauthor of Mime and IMAP RFCs)
  • making sure that malformed message will not result in buffer overun or other application crash
  • handling hierarchical messages (message with attached messages)
  • making sure that it handles correctly very big emails

这种解析器的成熟需要数年时间,并需要持续不断地为其用户提供反馈.目前 .NET Framework 中还没有这样的解析器.在它改变之前,我建议从一个成熟的供应商那里获得一个第三方 MIME 解析器.

Maturing of such parser takes years and continuous feedback for it's users. Right now is no such parser included in the .NET Framework. Until it changes I would sugest getting a thrid party MIME parser from an established vendor.

以下代码使用我们的 Rebex Secure Mail 组件,但我确信其他供应商的组件也可以轻松复制类似的任务.

Following code uses our Rebex Secure Mail component, but I'm sure that similar task could be replicated easily with components from other vendors as well.

代码基于邮件消息教程.

// create an instance of MailMessage 
MailMessage message = new MailMessage();

// load the message from a local disk file 
message.Load("c:\message.eml");

// send message
Smtp.Send(message, "smtp.example.org");

这篇关于发送保存在磁盘上的 eml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)