Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attachment's name is wrong decoded if norwegian letters are used

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.

enter image description here

If I remove norwegian letters, everything is ok

enter image description here

        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

like image 312
podeig Avatar asked May 03 '12 15:05

podeig


1 Answers

here is resolution from microsoft for .net framework 4

http://support.microsoft.com/kb/2402064

like image 95
Saar Avatar answered Nov 04 '22 16:11

Saar