MimeKit默认使用“encoded word”生成附件文件名
“name*=iso-8859-1''Testfile%20with%20%E6%20%F8%20og%20%E5.pdfå.pdf的测试文件”成为测试文件
我想要name="=?utf-8?B?VGVzdGZpbGUgd2l0aCDDpiDDuCBvZyDDpS5wZGY=?=“
下面是一些示例代码。您可以在生成的eml-file中看到结果
MimeKit.AttachmentCollection vedhaeftedefiler = new MimeKit.AttachmentCollection();
vedhaeftedefiler.Add(@"d:\temp\Testfile with æ ø og å.pdf");
var email = new MimeKit.MimeMessage();
email.From.Add(new MimeKit.MailboxAddress("John Doe", "john@example.com"));
email.Subject = "testsubject";
email.To.Add(new MimeKit.MailboxAddress("John Doe", "john@example.com"));
var bodyBuilder = new MimeKit.BodyBuilder();
bodyBuilder.TextBody = "Hello John";
foreach (var a in vedhaeftedefiler)
{
bodyBuilder.Attachments.Add(a);
}
email.Body = bodyBuilder.ToMessageBody();
email.Body.Prepare(MimeKit.EncodingConstraint.EightBit);
email.WriteTo(@"d:\temp\MimeKitTest_ " + DateTime.Now.ToString("yyMMdd hhmmss") + ".eml");发布于 2019-09-10 20:33:18
您可以像这样覆盖参数编码的行为:
var attachments = new AttachmentCollection ();
var attachment = attachments.Add(@"d:\temp\Testfile with æ ø og å.pdf");
foreach (var parameter in attachment.ContentType.Parameters)
parameter.EncodingMethod = ParameterEncodingMethod.Rfc2047;
foreach (var parameter in attachment.ContentDisposition.Parameters)
parameter.EncodingMethod = ParameterEncodingMethod.Rfc2047;https://stackoverflow.com/questions/57868704
复制相似问题