【发布时间】:2018-02-18 05:43:20
【问题描述】:
有许多从文件添加附件的好例子,但我想知道我是否可以以与AlternateView.CreateAlternateViewFromString 的工作方式类似的方式来做到这一点。
我分别使用 IMAP 从一个地址获取电子邮件的 body_text 和 body_headers,然后希望从另一个地址(通过 SMTP)发送它并进行一些更改,但尽可能忠实地添加附件。我正在使用 MailMessage 和 SmtpClient(System.Net 和 System.Net.Mail)
我编写了代码,通过它们的“Content-Type:”标签从 BODY[TEXT] 中提取 MIME 部分,并以这种方式愉快地将纯文本添加到 html 视图中。我在 MIME 中也有附件(请参见下面的示例),所以看起来我应该能够直接从我可以使用“Content-Type: application/octet-stream”从 MIME 中提取的字符串中轻松添加附件。目前,我只对它与 application/octet-stream 一起使用感兴趣。
我在我的部分代码中有这个可用的字符串,其中包含:
Content-Type: application/octet-stream; name="test_file.abc"
Content-Disposition: attachment; filename="test_file.abc"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_j7datrbn0
YWJjIGZpbGU=
或者
Content-Disposition: attachment; filename="test_file.abc"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_j7datrbn0
YWJjIGZpbGU=
来自示例:
* 53 FETCH (BODY[TEXT] {614}
--001a1140ae52fcc4690558c101ec
Content-Type: multipart/alternative; boundary="001a1140ae52fcc4630558c101ea"
--001a1140ae52fcc4630558c101ea
Content-Type: text/plain; charset="UTF-8"
Blah blah
--001a1140ae52fcc4630558c101ea
Content-Type: text/html; charset="UTF-8"
<div dir="ltr">Blah blah</div>
--001a1140ae52fcc4630558c101ea--
--001a1140ae52fcc4690558c101ec
Content-Type: application/octet-stream; name="test_file.abc"
Content-Disposition: attachment; filename="test_file.abc"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_j7datrbn0
YWJjIGZpbGU=
--001a1140ae52fcc4690558c101ec--
)
$ OK Success
我的代码的所有其他方面都有效,但是有没有一种简单的方法可以直接从我拥有的 MIME 数据中添加附件。我没有使用 MimeKit 或标准 VS 以外的任何库。
感谢您阅读这么长的问题。
【问题讨论】:
标签: email attachment mime mailmessage