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; }
我也遇到这个问题了已经解决
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就解决了
Good
好好检查编码。
把FileName进行URL编码。
我现在也遇到这个问题,请问下,您是怎么解决的? 求回复。
最后火狐还是乱码 google和IE好了 用了url编码
@_York: 你具体是怎么做的啊?有代码不啊?
@fulltimetoll: 看我发在下面的评论,我找到解决办法了
mark~~~