首页 新闻 会员 周边 捐助

webApi MailKit 发送邮件附件,中文附件名在QQ邮箱乱码

0
悬赏园豆:60 [已解决问题] 解决于 2018-01-24 11:55
public static IList<MimePart> GetMimePartList()
{
IList<MimePart> mimePartList = new List<MimePart>();
var current = HttpContext.Current;
if (current != null)
{
HttpRequest request = current.Request;
HttpFileCollection files = request.Files;
int filesCount = files.Count;
for (int i = 0; i < filesCount; i++)
{
HttpPostedFile item = files[i];
MimePart attachment = new MimePart(item.ContentType)
{
ContentObject = new ContentObject(item.InputStream, ContentEncoding.Default),
ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
ContentTransferEncoding = ContentEncoding.Base64,
FileName = item.FileName
};

mimePartList.Add(attachment);
}
}
return mimePartList;
}
_York的主页 _York | 初学一级 | 园豆:38
提问于:2017-06-02 11:10
< >
分享
最佳答案
0

我也遇到这个问题了已经解决

   AttachmentCollection attachmentCollection = new AttachmentCollection();

            string fileName = Path.GetFileName(path);

            var attachment = new MimePart(new ContentType("image", "png"))
            {
                Content = new MimeContent(new FileStream(path, FileMode.Open, FileAccess.Read)),
                ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
                ContentTransferEncoding = ContentEncoding.Base64,
                // FileName =  fileName,

            };

            attachment.ContentType.Parameters.Add("GB18030", "name", fileName);
            attachment.ContentDisposition.Parameters.Add("GB18030", "filename", fileName);

            attachmentCollection.Add(attachment);

问题不是出在mailkit上,只有qq邮箱才会乱码,在添加附件时将附件名的编码强指定为gb18030就解决了

收获园豆:60
RocketRobin | 菜鸟二级 |园豆:262 | 2018-01-23 13:58

Good

_York | 园豆:38 (初学一级) | 2018-01-24 11:55
其他回答(4)
0

好好检查编码。

花飘水流兮 | 园豆:13617 (专家六级) | 2017-06-03 00:49
0

把FileName进行URL编码。

幻天芒 | 园豆:37207 (高人七级) | 2017-06-03 09:11
0

我现在也遇到这个问题,请问下,您是怎么解决的? 求回复。

New Edition | 园豆:202 (菜鸟二级) | 2017-10-25 11:08

最后火狐还是乱码  google和IE好了   用了url编码

支持(0) 反对(0) _York | 园豆:38 (初学一级) | 2017-10-25 12:50

@_York: 你具体是怎么做的啊?有代码不啊?

支持(0) 反对(0) fulltimetoll | 园豆:200 (初学一级) | 2017-12-02 14:33

@fulltimetoll: 看我发在下面的评论,我找到解决办法了

支持(0) 反对(0) RocketRobin | 园豆:262 (菜鸟二级) | 2018-01-23 13:58
0

mark~~~

大漠孤阳 | 园豆:186 (初学一级) | 2018-07-03 13:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册