在C#中设置电子邮件附件名称 [英] Set Email Attachment name in C#

查看:199
本文介绍了在C#中设置电子邮件附件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加如下附件:

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

但是我想让它作为一个不同的名称附加,实际的文件名很长,很混乱我希望它作为file.txt附加,是否有一个简单的方法来做,而不必复制该文件?

But I want to make it attach as a different name, the actual file name is very long and confusing I would like it to attach as "file.txt", is there an easy way to do this without having to make a copy of the file?

推荐答案

如何:

System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(attachmentPath);
attachment.Name = "file.txt";  // set name here
msg.Attachments.Add(attachment);

这篇关于在C#中设置电子邮件附件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆