Set Email Attachment name in C#

前端 未结 2 567
无人共我
无人共我 2021-02-11 13:00

I add an attachment like this:

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


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-02-11 13:36

    You need to load the attachment from a stream and then you can give it a name and a media type.

    var fs = new FileStream("attachmentPath", FileMode.Open);
    var attachment = new System.Net.Mail.Attachment(fs, "MyAttachmentName.txt", "text/text");
    

提交回复
热议问题