Mimekit outlook显示文本作为附件

本文关键字:文本 outlook 显示 Mimekit | 更新日期: 2023-09-27 18:08:39

我有一个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);
}

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

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

查看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"?

提前感谢。

爱德华

Mimekit outlook显示文本作为附件

=3D位是=字符的quoted-printable编码。由于头文件正确地将Content-Transfer-Encoding声明为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;