2013-06-28 7 views
7

Azure WebまたはWorkerロールでSmtpClientを使用するときに例外が発生します。AzureロールでSmtpClientを使用すると「要求された機能がサポートされていません」という例外が発生する

私は手動で再現するためにRDP経由役割のVM上で実行するコンソールアプリケーションを作成しました:

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("[email protected]", "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("[email protected]"); 
     message.To.Add(new MailAddress("[email protected]")); 

     message.Subject = "testing " + DateTime.UtcNow; 
     message.Body = "The quick brown fox jumped over the lazy dogs."; 

     mailClient.Send(message); 
     } 
    } 
} 

ローカルそれだけで罰金電子メールを送信します。 Azureの上で私はこれを取得:

 
    Unhandled Exception: System.Net.Mail.SmtpException: Failure sending mail. ---> System.ComponentModel.Win32Exception: The function requested is not supported 
     at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode) 
     at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob) 
     at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie, String spn, ChannelBinding channelBindingToken) 
     at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) 
     at System.Net.Mail.SmtpClient.Send(MailMessage message) 
     --- End of inner exception stack trace --- 
     at System.Net.Mail.SmtpClient.Send(MailMessage message) 
     at ConsoleApplication1.Program.Main() in c:\development\ConsoleApplication1\ConsoleApplication1\Program.cs:line 39 

を私はAzureのマシンは、RDP経由でAzureの役割にTCPing.exeを実行して、メールサーバーのポート587にアクセスできることを確認しました。

答えて

5

明らかにこの問題は、サーバー間のNTLMバージョンの不一致が原因でした。

Azureの役割にログインして設定を無効にした後

は、クライアントのために、 "NTLMv2のセキュリティを要求する"、それが働いた:

enter image description here

(感謝this answerとインスピレーションのためのthis answerに。)現在

SMTPサーバーをNTLMv2互換にアップグレードできるかどうかを確認します。それ以外の場合は、自動生成されたコードを設定して、生成された各ロールインスタンスでその設定を無効にする必要があります。

明らかにこのコードは先月働いた。だから私は最近のAzure OSのアップグレードがデフォルト設定を変更したと推測しています。設定を自動化するには20000000

FYI:この設定のレジストリキーが

ある[ます。HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \コントロール\ Lsaに\ MSV1_0] "NtlmMinClientSec" = DWORDこのようreg addコマンドを含むレジストリキーadd a startup task

reg add HKLM\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0^
/v NtlmMinClientSec^
/t REG_DWORD^
/d 0x20000000^
/f 

の場合、/fは現在の設定を強制的に上書きします。^は、読みやすくするためにコマンドを複数の行に分けることができます。また、issues during role startupを防ぐために、ASCIIエンコーディングでコマンドを保存してください。

関連する問題