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);

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...