2013-06-28 21 views
7

Bir Azure Web veya Worker rolünde SmtpClient kullanırken bir istisna alıyorum. "İstenen işlev desteklenmiyor" istisnası Azure rolünde SmtpClient rolü kullanılıyor

el çoğaltmak RDP aracılığıyla rolü VM'lerin üzerinde çalıştırmak için bir konsol uygulaması oluşturulur:

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); 
     } 
    } 
} 

Yerel it email gayet gönderir.

 
    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 

ben Azure makineleri RDP aracılığıyla Azure roller TCPing.exe çalıştırarak posta sunucusunda bağlantı noktası 587 erişebilmesini teyit ettik: Azure üzerinde bu olsun.

cevap

5

Görünüşe göre sorun, sunucular arasında eşleşmeyen bir NTLM sürümüydi.

Azure rollere girerek ve ayarı devre dışı bıraktıktan sonra

müşterileri için "NTLMv2 güvenliğini iste", o zaman çalıştı:

enter image description here

(teşekkürler this answer ve ilham almak için this answer için.) Şu

SMTP sunucumuzu NTLMv2 uyumlu olacak şekilde yükseltip yükseltemeyeceğimizi görmek. Aksi takdirde, her bir oluşturulan rol örneğinde bu ayarı devre dışı bırakmak için bazı otomatik kodlar ayarlamamız gerekecek.

Görünüşe göre bu kod geçen ay çalıştı. Bu yüzden son zamanlarda Azure OS yükseltmesinin varsayılan ayarları değiştirdiğini tahmin ediyorum.

Bilginize: Bu ayar için kayıt defteri anahtarı

olduğunu [HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ lsa \ msv1_0] "NtlmMinClientSec" = dword: 20000000

ayarı otomatik hale getirmek için böyle bir reg add komutu içeren kayıt defteri anahtarı add a startup task:

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

/f'un geçerli ayarın üzerine yazılmasını zorlar ve ^ sadece daha iyi okunabilirlik için komutun birden fazla satıra bölünmesine izin verir. Ayrıca, issues during role startup'u önlemek için ASCII kodlamada komutu sakladığınızdan emin olun.

İlgili konular