用MailMessage发送邮件,html格式会有乱码?

flyxing 2006-10-30 03:11:30
代码如下,组合好的html也没有问题,但是收下来的邮件隔一段就会有个空格或者有一小段乱码,哪位大虾帮忙看看什么原因?谢谢

public static bool SendMail(string p_strSubject,string p_strMsg,string p_strReceiver,string p_strSender,string p_strType)
{
try
{
if(Server==null||Server=="")
InitMailSender();
MailMessage msg=new MailMessage();
msg.Subject=p_strSubject;
msg.From=p_strSender;
msg.To=p_strReceiver;
if(p_strType=="html")
msg.BodyFormat=MailFormat.Html;
else
msg.BodyFormat=MailFormat.Text;

msg.Body=p_strMsg;

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", Server);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", ServerPort);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Account);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password);
SmtpMail.Send(msg);
return true;
}
catch
{
return false;
}
}
...全文
623 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyxing 2006-11-02
  • 打赏
  • 举报
回复
解决了,发现是邮件服务器每隔定长就增加了一个换行,所以干脆在组合的时候手工给他加了换行就好了
贝贝壳壳 2006-10-30
  • 打赏
  • 举报
回复
哦,没有GB2312, 那就用Default
贝贝壳壳 2006-10-30
  • 打赏
  • 举报
回复
设置一下
msg.BodyEncoding= Encoding.UTF8 ;//或者Unicode,ASCII,GB2312...

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧