读书人

Net.Mail发送邮件附件成为了乱码(da

发布时间: 2013-07-09 09:50:47 作者: rapoo

Net.Mail发送邮件,附件变成了乱码(dat文件)
代码:


string strSmtpServer = smtpServer;
string strFrom = mailFrom;
string strMailProxyUser = mailProxyUser;
string strMailProxyPass = mailProxyPassword;
SmtpClient client = new SmtpClient(strSmtpServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strMailProxyUser, strMailProxyPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.Timeout = 3000000;
MailAddress from = new MailAddress(strFrom);
MailAddress to = new MailAddress(strTo, strToDisplayName);
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
message.Subject = strSubject;
message.Body = strBody;
System.Net.Mail.Attachment attachment = null;
message.SubjectEncoding = Encoding.UTF8;
message.HeadersEncoding = Encoding.UTF8;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
if (attachmentFiles != null)
{
foreach (string files in attachmentFiles)
{
if (System.IO.File.Exists(files))
{
attachment = new System.Net.Mail.Attachment(files);
attachment.NameEncoding = Encoding.UTF8;
message.Attachments.Add(attachment);


}
}
}

try
{
client.Send(message);
}
catch (Exception ex)
{
DebugWrite("发送邮件出现问题了" + ex.ToString());
}
finally
{
foreach (Attachment item in message.Attachments)
{
item.Dispose();
}
if (attachment != null)
{
attachment.Dispose();
}
message.Dispose();
}



下面是附件出现的乱码:
=?utf-8?B?byttVWdPUzRrK2FJdCtXZnV1bUhrZWkxPz0NCiA9P3V0Zi04P0I/aE9T?=\
\
=?utf-8?B?NnArUzhzT1dBdk9paHFESXdNVE13TmpFM0xuaHNjdz09Pz0=?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment

我本机测试是没有问题的,但是部署到服务器上发送邮件时,附件就会出现乱码,正文和标题都是正常的。

自己估计:可能跟附件的名称是中文有关系,但是不知道如何修改。

请求指点。


[解决办法]
没遇到过,帮顶下
[解决办法]
引用:

http://blog.sina.com.cn/s/blog_62fda93c010191fc.html

这楼可以看
[解决办法]
嗯,,百度了很久,,这个http://blog.sina.com.cn/s/blog_62fda93c010191fc.html 真的不错

读书人网 >asp.net

热点推荐