Set Email Attachment name in C#

前端 未结 2 566
无人共我
无人共我 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");
    
    0 讨论(0)
  • 2021-02-11 13:49

    How about:

    System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(attachmentPath);
    attachment.Name = "file.txt";  // set name here
    msg.Attachments.Add(attachment);
    
    0 讨论(0)
提交回复
热议问题