【问题标题】:System.Net.Mail and authentication headersSystem.Net.Mail 和身份验证标头
【发布时间】: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 现在正在幕后执行所有这些操作?

【问题讨论】:

  • 不确定实际问题是什么。你遇到了什么错误?

标签: c# email smtp smtp-auth


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-09-09
    • 2019-06-19
    • 2021-09-26
    • 2015-03-07
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 2014-05-20
    相关资源
    最近更新 更多