我有这段代码可以创建附件并发送电子邮件。如果文件名包含 æ、ø 或 æ,则该文件名将被完全销毁。
如果我删除挪威字母,一切正常
var stream = new MemoryStream();
doc.Save(stream, SaveFormat.Docx);
mail.From = new MailAddress("no-replay@email.no");
mail.To.Add("my@email.no");
mail.IsBodyHtml = true;
mail.Subject = "Attachments test";
mail.Body = "Hei,<br /><br />";
stream.Seek(0, SeekOrigin.Begin);
var attachment = new Attachment(stream, "Name Å Æ Ø.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
attachment.NameEncoding = Encoding.UTF8;
mail.Attachments.Add(attachment);
var smtp = new SmtpClient("smtp.server.com") {Port = 25};
smtp.Send(mail);
如何正确完成这项工作?
解决方案
我在这里找到了一个解决方案http://social.msdn.microsoft.com/Forums/en-US/dotnetframeworkde/thread/b6c764f7-4697-4394-b45f-128a24306d55