Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;不支持请求的功能";在Azure角色中使用SmtpClient时出现异常_C#_.net_Azure_Smtpclient - Fatal编程技术网

C# &引用;不支持请求的功能";在Azure角色中使用SmtpClient时出现异常

C# &引用;不支持请求的功能";在Azure角色中使用SmtpClient时出现异常,c#,.net,azure,smtpclient,C#,.net,Azure,Smtpclient,在Azure Web或工作者角色中使用SmtpClient时出现异常 我创建了一个控制台应用程序,通过RDP在角色VM上手动运行,以再现: using System; using System.Net; using System.Net.Mail; using System.Text; namespace ConsoleApplication1 { class Program { static void Main() { var mailC

在Azure Web或工作者角色中使用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("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上,我得到以下信息:

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 未处理的异常:System.Net.Mail.SmtpException:发送邮件失败。-->System.ComponentModel.Win32异常:不支持请求的函数 在System.Net.nAuthentication.GetOutgoingBlob(字节[]incomingBlob,布尔throwOnError,SecurityStatus和statusCode) at System.Net.nAuthentication.GetOutgoingBlob(字符串incomingBlob) 在System.Net.Mail.SmtpNtlmAuthenticationModule.Authentication(字符串质询、网络凭据凭据、对象会话令牌、字符串spn、通道绑定令牌) 位于System.Net.Mail.SmtpConnection.GetConnection(ServicePoint ServicePoint) 在System.Net.Mail.SmtpClient.Send(邮件消息)上 ---内部异常堆栈跟踪的结束--- 在System.Net.Mail.SmtpClient.Send(邮件消息)上 在c:\development\ConsoleApplication1\ConsoleApplication1\Program.cs中的ConsoleApplication1.Program.Main()处:第39行
我已经确认Azure机器可以通过RDP在Azure角色上运行TCPing.exe来访问邮件服务器上的端口587。

因此,问题显然是服务器之间的NTLM版本不匹配

在登录Azure角色并禁用客户端的“要求NTLMv2安全性”设置后,该设置起到了作用:

(感谢并获得了灵感。)

目前正在查看是否可以将SMTP服务器升级为与NTLMv2兼容。否则,我们将不得不设置一些自动代码,以便在每个生成的角色实例上以某种方式禁用该设置

显然这个代码上个月起作用了。所以我猜最近的Azure OS升级更改了默认设置

仅供参考:此设置的注册表项为

[HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1\U 0] “NtlmMinClientSec”=dword:20000000

要自动设置包含
reg add
命令的注册表项,请执行以下操作:

reg add HKLM\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0 ^
 /v NtlmMinClientSec ^
 /t REG_DWORD ^
 /d 0x20000000 ^
 /f
其中,
/f
强制覆盖当前设置,
^
只允许将命令分成多行,以提高可读性。还要确保将命令保存为ASCII编码,以防止错误