在 C# 中设置电子邮件附件名称
我添加这样的附件:
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(AttachmentPath);
msg.Attachments.Add(attachment);
但我想将其附加为不同的名称,实际文件名非常长且令人困惑我希望将其附加为“file.txt”,有没有一种简单的方法可以做到这一点而不需要必须复制文件吗?
I add an attachment like this:
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(AttachmentPath);
msg.Attachments.Add(attachment);
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
怎么样:
How about:
您需要从流中加载附件,然后可以为其指定名称和媒体类型。
You need to load the attachment from a stream and then you can give it a name and a media type.
所以我所做的基本上就是创建附件并在初始化中添加名称。
So what I did was basically to create the attachment and add the name in the initialization.