以下功能完美运行:
protected void SendWebMailMessage(string DisplayName, string From, string ReplyTo,
string To, string Subject, string Body, string Attachments)
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver",
"smtpout.secureserver.net");
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",
2);
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername", From);
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword",
mailpassword);
msg.To = To;
msg.From = DisplayName + "<" + From + ">";
msg.BodyFormat = MailFormat.Html;
msg.Subject = Subject;
msg.Body = Body;
msg.Headers.Add("Reply-To", ReplyTo);
SmtpMail.SmtpServer = "smtpout.secureserver.net";
SmtpMail.Send(msg);
}
但是,我收到一个构建警告,告诉我 System.Web.Mail 已过时,我应该使用 System.Net.Mail。所以我使用了 System.Net.Mail,我想出了以下函数来替换我的旧函数:
protected void SendNetMailMessage(string DisplayName, string From, string ReplyTo,
string To, string Subject, string Body, string Attachments)
{
MailAddress addrfrom = new MailAddress(From, DisplayName);
MailAddress addrto = new MailAddress(To);
MailAddress replytoaddr = new MailAddress(ReplyTo);
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = addrfrom;
msg.To.Add(addrto);
msg.ReplyTo = replytoaddr;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtpout.secureserver.net");
smtp.Credentials = new NetworkCredential(From, mailpassword);
smtp.Send(msg);
}
我没有收到任何异常或错误,但我的消息永远不会通过。谁能告诉我我可能做错了什么?提前致谢。