0

我有一个 word 文档并使用 Aspose.Word 执行邮件合并并将结果作为 mhtml(我的代码的一部分)保存到内存流中:

Aspose.Words.Document doc = new Aspose.Words.Document(documentDirectory + countryLetterName);
doc.MailMerge.Execute(tempTable2);
MemoryStream outStream = new MemoryStream();
doc.Save(outStream, Aspose.Words.SaveFormat.Mhtml);

然后我使用 MimeKit(来自 NuGet 的最新版本)发送我的消息:

outStream.Position = 0;
MimeMessage messageMimeKit = MimeMessage.Load(outStream);
messageMimeKit.From.Add(new MailboxAddress("<sender name>", "<sender email"));
messageMimeKit.To.Add(new MailboxAddress("<recipient name>", "<recipient email>"));
messageMimeKit.Subject = "my subject";
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
    client.Connect(<smtp server>, <smtp port>, true);
    client.Authenticate("xxxx", "pwd");
    client.Send(messageMimeKit);
    client.Disconnect(true);
}

在我的邮件网络客户端中打开收到的电子邮件时,我看到文本(带图像)和图像作为附件。

在 Outlook (2016) 中打开收到的电子邮件时,邮件正文为空,我有两个附件,1 个带有文本,1 个带有图像。

查看 mht 内容本身,它看起来像:

MIME-Version: 1.0
Content-Type: multipart/related;
    type="text/html";
    boundary="=boundary.Aspose.Words=--"

This is a multi-part message in MIME format.

--=boundary.Aspose.Words=--
Content-Disposition: inline;
    filename="document.html"
Content-Type: text/html;
    charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Location: document.html

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=
=3Dutf-8" /><meta http-equiv=3D"Content-Style-Type" content=3D"text/css" />=
<meta name=3D"generator" content=3D"Aspose.Words for .NET 14.1.0.0" /><titl=
e></title></head><body>
*****body removed *****
</body></html>

--=boundary.Aspose.Words=--
Content-Disposition: inline;
    filename="image.001.jpeg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: image.001.jpeg

****image content remove****

--=boundary.Aspose.Words=----

是否有一些格式,或者我必须做些什么才能在 Outlook 中正确显示?还是由找到的“3D”关键字引起的,例如 content=3D"xxxx", style=3D"xxxx"?

提前致谢。

爱德华

4

1 回答 1

0

这些=3D位是字符的quoted-printable编码=。由于标头正确地声明了Content-Transfer-Encodingto quoted-printable,所以这不是问题。

以下是一些关于尝试将内容按摩到可以在 Outlook 中工作的内容的建议(Outlook 非常挑剔):

MimeMessage messageMimeKit = MimeMessage.Load(outStream);
messageMimeKit.From.Add(new MailboxAddress("<sender name>", "<sender email"));
messageMimeKit.To.Add(new MailboxAddress("<recipient name>", "<recipient email>"));
messageMimeKit.Subject = "my subject";

var related = (MultipartRelated) messageMimeKit.Body;
var body = (MimePart) related[0];

// It's possible that the filename on the HTML body is confusing Outlook.
body.FileName = null;

// It's also possible that the Content-Location is confusing Outlook
body.ContentLocation = null;
于 2016-09-26T18:07:01.387 回答