使用SmtpClient发送一个文件附件 [英] Using SmtpClient to send a file attachment

查看:457
本文介绍了使用SmtpClient发送一个文件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 SmtpClient 类来发送邮件,并附加文件。一切似乎都做工精细,除了在电子邮件附件中的文件名称 filestest.docx 而不是 test.docx 的。这是默认的附加文件夹名称,该文件位于下。我想只看到实际的文件名。

I am using the SmtpClient class to send mail and also attach files. Everything seems to work fine, except that the filename in the email attachment says filestest.docx instead of test.docx. It is by default appending the folder name the file is located under. I would like to see only the actual file name.

msg.Attachments.Add(new Attachment("I:/files/test.docx"));

任何想法?

推荐答案

添加的ContentType 以您的附件。

System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType();
contentType.MediaType = System.Net.Mime.MediaTypeNames.Application.Octet;
contentType.Name = "test.docx";
msg.Attachments.Add(new Attachment("I:/files/test.docx"), contentType);
...

这篇关于使用SmtpClient发送一个文件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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