Using SmtpClient to send an attachment file

I use the SmtpClient class to send mail as well as attach files. Everything seems to be working fine, except that the file name in the email application indicates filestest.docx instead of test.docx . By default, the name of the folder in which the file is located is added. I would like to see only the actual file name.

 msg.Attachments.Add(new Attachment("I:/files/test.docx")); 

Any ideas?

+6
source share
1 answer

Add ContentType to your application.

 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)); ... 
+13
source

Source: https://habr.com/ru/post/949574/


All Articles