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
mail
aMailMessage
? If so, could you check if all "encoding" properties, likeBodyEncoding
,HeadersEncoding
and so on, have the same value? – Centenary