使用SmtpClient发送文件附件
我正在使用SmtpClient
类发送邮件并附加文件。 除了电子邮件附件中的文件名是filestest.docx
而不是test.docx
之外,一切似乎都运行正常。 默认情况下,它附加文件所在的文件夹名称。 我只想看到实际的文件名。
msg.Attachments.Add(new Attachment("I:/files/test.docx"));
有任何想法吗?
将ContentType添加到附件中。
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)); ...