我尝试使用System.Net.Mail.Attachment发送System.Net.Mail.MailMessage.
附件名称是“Счёт-договор№4321от4июля.pdf”
附件创建代码:
var nameEncoding = Encoding.UTF8; return new System.Net.Mail.Attachment(new MemoryStream(bytes),MessageBodiesHelpers.EncodeAttachmentName(fileName,nameEncoding),attachment.MediaType) { TransferEncoding = TransferEncoding.Base64,NameEncoding = nameEncoding };
MessageBodiesHelpers.EncodeAttachmentName中的代码取自https://social.msdn.microsoft.com/Forums/en-US/b6c764f7-4697-4394-b45f-128a24306d55/40-smtpclientsend-attachments-mit-umlauten-im-dateinamen?forum=dotnetframeworkde
如果我将附件发送到gmail或ms交换,则附件的名称解析成功.但!
如果我将该附件发送到icloud,那么我得到“???? ????№4321от4????.pdf”
从ms交换:
Content-Type: application/pdf; name="=?utf-8?B?0KHRh9GR0YIt0LTQ?==?utf-8?B?vtCz0L7QstC+0YAg?==?utf-8?B?4oSWNDMyMSDQvtGC?==?utf-8?B?IDQg0LjRjtC70Y8u?==?utf-8?B?cGRm?=" Content-Transfer-Encoding: base64 Content-Disposition: attachment
从icloud:
Content-Transfer-Encoding: BASE64 Content-Type: APPLICATION/PDF; name="????-??????? =?utf-8?B?4oSWNDMyMSDQvtGC?= 4 ????.pdf"
如何格式化icloud的名称?
UPD
如果我将outlook(ms交换)的消息转发到icloud,则附件的名称解析成功.头:
Content-Transfer-Encoding: BASE64 Content-Disposition: ATTACHMENT; size=200702; modification-date="Mon,04 Jul 2016 13:40:22 GMT"; filename*=utf-8''%D0%A1%D1%87%D1%91%D1%82%2D%D0%B4%D0%BE%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%20%E2%84%964321%20%D0%BE%D1%82%204%20%D0%B8%D1%8E%D0%BB%D1%8F.pdf; creation-date="Mon,04 Jul 2016 13:40:22 GMT" Content-Type: APPLICATION/PDF; name*=utf-8''%D0%A1%D1%87%D1%91%D1%82%2D%D0%B4%D0%BE%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%20%E2%84%964321%20%D0%BE%D1%82%204%20%D0%B8%D1%8E%D0%BB%D1%8F.pdf
UPD2
如果我使用icloud(icloud.com)的Web界面阅读消息,则附件的名称解析成功.