Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Email Attachment name in C#

I add an attachment like this:

System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(AttachmentPath);    msg.Attachments.Add(attachment);    

But I want to make it attach as a different name, the actual file name is very long and confusing I would like it to attach as "file.txt", is there an easy way to do this without having to make a copy of the file?

like image 237
Tom Gullen Avatar asked Aug 22 '11 14:08

Tom Gullen


1 Answers

How about:

System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(attachmentPath); attachment.Name = "file.txt";  // set name here msg.Attachments.Add(attachment); 
like image 128
Kev Avatar answered Sep 21 '22 10:09

Kev