//attachment = new Attachment(path, MediaTypeNames.Application.Octet); //attachment.Name = System.IO.Path.GetFileName(path); //attachment.NameEncoding = Encoding.GetEncoding("gb2312");// //attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64; //attachment.ContentDisposition.Inline = true; //attachment.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Inline; string extName = Path.GetExtension(fileName); if (extName == ".zip" || extName == ".rar") { attachment = new System.Net.Mail.Attachment(new FileStream(path, FileMode.Open, FileAccess.Read), fileName, MediaTypeNames.Application.Zip); } else { attachment = new System.Net.Mail.Attachment(new FileStream(path, FileMode.Open, FileAccess.Read), fileName, MediaTypeNames.Application.Octet); } //string cid = attachment.ContentId;//关键性的地方,这里得到一个id数值 //ContentDisposition disposition = attachment.ContentDisposition; //disposition.CreationDate = System.IO.File.GetCreationTime(path); //disposition.ModificationDate = System.IO.File.GetLastWriteTime(path); //disposition.ReadDate = System.IO.File.GetLastAccessTime(path); mailMessage.Attachments.Add(attachment);
在网页中打开邮件,附件中文名就出现乱码
Firefox正常
见图;
谢谢!!
估计是附件的正文的编码方式跟附件名的编码方式不一致吧,检查一下,把各个部分的编码方式统一起来。