Azure Web またはワーカー ロールで SmtpClient を使用すると、例外が発生します。
ロール VM で RDP 経由で手動で実行して再現するコンソール アプリを作成しました。
using System;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
var mailClient = new SmtpClient("mail.redacted.com", 587);
mailClient.EnableSsl = true;
mailClient.DeliveryFormat = SmtpDeliveryFormat.International;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.UseDefaultCredentials = false;//SET THIS FIRST OR IT WIPES OUT CREDENTIALS
NetworkCredential netCreds = new NetworkCredential("mail@redacted.com", "12345 same combination on my luggage");
mailClient.Credentials = netCreds;
MailMessage message = new MailMessage();
message.SubjectEncoding = Encoding.UTF8;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = false;
message.From = new MailAddress("mike@redacted.com");
message.To.Add(new MailAddress("mike@redacted.com"));
message.Subject = "testing " + DateTime.UtcNow;
message.Body = "The quick brown fox jumped over the lazy dogs.";
mailClient.Send(message);
}
}
}
ローカルでは問題なくメールを送信します。Azure では、次のようになります。
未処理の例外: System.Net.Mail.SmtpException: メールの送信に失敗しました。---> System.ComponentModel.Win32Exception: 要求された関数はサポートされていません System.Net.NTAuthentication.GetOutgoingBlob で (Byte[] incomingBlob、ブール値の throwOnError、SecurityStatus& statusCode) System.Net.NTAuthentication.GetOutgoingBlob (着信 Blob の文字列) で System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate (文字列チャレンジ、NetworkCredential 資格情報、オブジェクト sessionCookie、文字列 spn、ChannelBinding channelBindingToken) で System.Net.Mail.SmtpConnection.GetConnection (ServicePoint servicePoint) で System.Net.Mail.SmtpClient.Send (MailMessage メッセージ) で --- 内部例外スタック トレースの終了 --- System.Net.Mail.SmtpClient.Send (MailMessage メッセージ) で c:\development\ConsoleApplication1\ConsoleApplication1\Program.cs:line 39 の ConsoleApplication1.Program.Main() で
Azure ロールで RDP 経由で TCPing.exe を実行することにより、Azure マシンがメール サーバーのポート 587 にアクセスできることを確認しました。