Excluded "Requested Feature Not Supported" feature when using SmtpClient as Azure

I get an exception when using SmtpClient in the role of Azure Web or Worker.

I created a console application to manually run on a VM role through RDP to play:

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

Locally he sends the email just fine. On Azure, I get the following:

  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

I confirmed that Azure machines can access port 587 on the mail server by running TCPing.exe in Azure roles through RDP.

+7
source share
1 answer

Apparently, the problem was an inconsistent version of NTLM between servers.

After entering the Azure role and disabling the "Require NTLMv2 security" option for clients, it worked:

enter image description here

(Thanks this answer and this answer for inspiration.)

We are currently seeing if we can upgrade our SMTP server for NTLMv2 compatibility. Otherwise, we will have to configure some automated code to somehow disable this parameter for each instance of the role created.

Apparently, this code worked last month. Therefore, I assume that the updated version of Azure OS has changed the default settings.

FYI: registry key for this parameter

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ LSA \ MSV1_0] "NtlmMinClientSec" = DWORD: 20000000

To automate the configuration of a registry key, add a launch task that contains the reg add command as follows:

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

where /f forcibly overwrites the current setting and ^ just allows you to split the command into several lines for better readability. Also, do not forget to save the command in ASCII encoding to prevent problems when starting the role .

+5
source

All Articles