c# – 如何为电子邮件(System.Net.Mail.SmtpClient)附件设置一个好名称

前端之家收集整理的这篇文章主要介绍了c# – 如何为电子邮件(System.Net.Mail.SmtpClient)附件设置一个好名称前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在C#中使用System.Net.Mail.SmtpClient发送附件.
附件名称与我传递给附件构造函数文件名相同
myMail.Attachments.Add(new Attachment(attachmentFileName));

我如何设置附件的“好”名称?我当前拥有的名称基本上是数字ID,表示附加了哪个报告.我的用户正在寻找更友好的东西,比如“results.xls”.

解决方法

Attachment.Name Property

Gets or sets the MIME content type name value in the content type associated with this attachment.

您可以将Attachment .Name属性设置为您喜欢的任何内容.在最后一个链接的示例中,您可以:

// Create  the file attachment for this e-mail message.
Attachment data = new Attachment(file,MediaTypeNames.Application.Octet);
data.Name = "VeryNiceName.dat"; //(not in original example)
...
message.Attachments.Add(data);
原文链接:https://www.f2er.com/csharp/98427.html

猜你在找的C#相关文章