1

I need to send email message with attachment. I'm using below code:

MailMessage msg = new MailMessage("adrFrom", "adrTo", "header", "body");

SmtpClient client = new SmtpClient("hostName", 25);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("accountName", "password");

Attachment atch = new Attachment(filePath, MediaTypeNames.Application.Octet);

atch.Name = "FileName.docx";

msg.Attachments.Add(atch);

client.Send(msg);

Message is received, and attachment is there too, but file name looks like ' =?utf-8?B?dXRHRDBZTFJnOUdBMFlzZzBKelF1TkNoPz0NCiA9P3V0Zi04P0I/TG1S?=\', also there is no extension(.docx) and file content looks like it's in the Base64 encoding. How can I send e-mail message with .docx file saving it extension and name?

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
Gleb
  • 1,412
  • 1
  • 23
  • 55

2 Answers2

1

Add Contentype to your Attachment

System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType();
contentType.MediaType = System.Net.Mime.MediaTypeNames.Application.Octet;
contentType.Name = "test.docx";
msg.Attachments.Add(new Attachment("I:/files/test.docx"), contentType);
Dhru 'soni
  • 1,024
  • 7
  • 23
0

I have found a solution

The problem was in Russian letters in the file name. Without it everything works fine.

Gleb
  • 1,412
  • 1
  • 23
  • 55
  • @MoslemBenDhaou yes, thats also solved by installing microsoft patch. http://support.microsoft.com/kb/2402064 – Gleb Mar 10 '15 at 10:49