c# - MimeKit howto base64 编码附件文件名
问题描述
MimeKit 默认使用“编码字”生成附件文件名
“带有æ ø og å.pdf 的测试文件”变为名称*=iso-8859-1''Testfile%20with%20%E6%20%F8%20og%20%E5.pdf
我想得到 name="=?utf-8?B?VGVzdGZpbGUgd2l0aCDDpiDDuCBvZyDDpS5wZGY=?="
这是一些示例代码。您可以在生成的 eml 文件中看到结果
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");
解决方案
您可以像这样覆盖参数编码的行为:
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;
推荐阅读
- huggingface-transformers - 减少 XLTransformers 的输出层大小
- java - 春天,休眠:java.sql.SQLSyntaxErrorException:表'test2.ciudad_persona'不存在
- sorting - 排序层完全没有效果
- php - 你如何在 PhpStorm 上使用 file_get_contents()?
- python - 我正在尝试用不同类型的水果训练我的模型
- arcgis-js-api - 使用 wkid 102704 时,ArcGIS 地图显示所有大陆(完全缩小)
- python - 从 Python boto3 对象派生位置信息
- python - 有没有办法让 Telepot 机器人读取来自其他机器人的消息?
- javascript - 如何使 var 输入在事件侦听器函数之外可用?(JS)
- python - 将数据读入 jupyter notebook