0

在旧项目中使用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 现在正在幕后做这一切?

4

1 回答 1

0

是的,您不必手动添加这些字段。

于 2014-08-26T10:21:06.587 回答