2016-09-25 57 views
0

我有一个word文档,并使用Aspose.Word执行邮件合并,结果到内存流保存为MHTML(我的代码部分):mimekit前景显示文本作为附件

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)中打开收到的电子邮件时,邮件正文为空,我有两个附件,其中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”?

在此先感谢。

爱德华

回答

0

=3D的位是=字符的quoted-printable编码。由于标题正确地声明Content-Transfer-Encodingquoted-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; 
+0

嗨杰弗里,遗憾的响应晚。谢谢你的回答。我已经将FileName和ContentLocation都设置为null,现在在Outlook中看起来很好。 – ET67