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);
}

受信したメールをメール Web クライアントで開くと、テキスト (画像付き) と画像が添付ファイルとして表示されます。

受信したメールを Outlook (2016) で開くと、メール本文が空で、2 つの添付ファイル (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 で正しく表示するには、何らかの書式設定を行う必要がありますか? それとも、content=3D"xxxx"、style=3D"xxxx" などの "3D" キーワードが原因ですか?

前もって感謝します。

エドワード

4

1 に答える 1

0

=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;
于 2016-09-26T18:07:01.387 に答える