问题描述
我正在创建 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!