Reputation: 2741
I have this piece of code which creates an attachment and sends email. If name of the file contains æ, ø or æ, the name is totally destroyed.
If I remove norwegian letters, everything is ok
var stream = new MemoryStream();
doc.Save(stream, SaveFormat.Docx);
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
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);
How to get this work properly?
SOLUTION
I found a solution here http://social.msdn.microsoft.com/Forums/en-US/dotnetframeworkde/thread/b6c764f7-4697-4394-b45f-128a24306d55
Upvotes: 10
Views: 3258
Reputation: 8474
here is resolution from microsoft for .net framework 4
http://support.microsoft.com/kb/2402064
Upvotes: 2
Reputation: 56536
Try changing attachment.NameEncoding = Encoding.UTF8;
to attachment.NameEncoding = Encoding.Unicode;
.
Upvotes: 0