【发布时间】:2014-10-19 14:51:55
【问题描述】:
在一个旧项目中使用System.Web.Mail 我曾经使用以下代码来构建经过身份验证的消息
MailMessage msg = new MailMessage();
// ... fill in to, from etc
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", Application["smtpserver"].ToString());
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Application["smtpserverport"].ToString());
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", Application["sendusername"].ToString());
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Application["sendpassword"].ToString());
System.Net.Mail 被推荐作为替代品,但它似乎已经取消了这些字段。
这是我的新电子邮件发送代码。
MailMessage em = new MailMessage();
// ... fill in to, from etc
// Init SmtpClient and send
SmtpClient smtpClient =
new SmtpClient(
AppSetting["smtpserver"],
Convert.ToInt32(AppSetting["smtpserverport"])
);
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(
AppSetting["sendusername"],
AppSetting["sendpassword"]
);
smtpClient.Credentials = credentials;
smtpClient.Send(em);
我怀疑 SmtpClient.Send 现在正在幕后执行所有这些操作?
【问题讨论】:
-
不确定实际问题是什么。你遇到了什么错误?