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