使用System.Web.Mail在C#中设置电子邮件附件名称 [英] Set Email Attachment name in C# with System.Web.Mail
问题描述
我无法使用System.Net.Mail ,因为我必须连接使用隐式SSL的服务器,但System.Net.Mail不支持它。
因此我很想使用旧的已弃用的图书馆
我添加这样的附件:
System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(AttachmentPath);
System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
....
mailMsg.Attachments.Add(附件);
但我想制作它附加为一个不同的名称:
实际文件名很长而且令人困惑,因为它是一个临时文件。
我希望它附加如SalesOrderNo1.pdf,
有没有办法做到这一点而不必制作文件副本,文件名冲突风险高?
我知道System.Net.Mail.Attachment有属性名称来设置附件标题。
而不是System.Web.Mail.MailAttachment只有 readonly 属性Filename返回加载的文件路径。
谢谢
I cannot use System.Net.Mail because I must connect with Servers that use Implicit SSL but System.Net.Mail does not support it.
Therefore I am forsed to use the old deprecated library too
I add an attachment like this:
System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(AttachmentPath);
System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
....
mailMsg.Attachments.Add(attachment);
But I want to make it attach as a different name:
the actual file name is very long and confusing because it is a temporary file.
I would like it to attach such as "SalesOrderNo1.pdf",
is there a way to do this without having to make a copy of the file with high risk of file name collision ?
I know that System.Net.Mail.Attachment has property Name to set attachment title.
Instead System.Web.Mail.MailAttachment only has a readonly property Filename returns loaded file path.
Thanks
推荐答案
这很好..
this works good..
attachment.Name = "SalesOrderNo1.pdf";
mailMsg.Attachments.Add(attachment);
这篇关于使用System.Web.Mail在C#中设置电子邮件附件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!