Using System.Web.Mail
in an old project I used to use the following code to build an authenticated message
在旧项目中使用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
is recommended as the replacement, but it seems to have done away with these fields.
建议使用System.Net.Mail作为替代品,但它似乎已经废除了这些字段。
Here's my new email sending code.
这是我的新电子邮件发送代码。
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);
I suspect that SmtpClient.Send is now doing all of this behind the scenes?
我怀疑SmtpClient.Send现在正在幕后做这一切吗?
1 个解决方案
#1
0
Yes, you don't have to add those fields manually.
是的,您不必手动添加这些字段。
#1
0
Yes, you don't have to add those fields manually.
是的,您不必手动添加这些字段。