Tôi nhận được ngoại lệ khi sử dụng SmtpClient trong vai trò Azure Web hoặc Worker."Chức năng được yêu cầu không được hỗ trợ" ngoại lệ khi sử dụng SmtpClient trong vai trò Azure
Tôi tạo ra một ứng dụng giao diện điều khiển bằng tay chạy trên vai trò máy ảo thông qua RDP để tái sản xuất:
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]acted.com");
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);
}
}
}
tại địa phương nó sẽ gửi một email tốt. Trên Azure tôi có được điều này:
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
Tôi xác nhận rằng các máy Azure có thể truy cập vào cổng 587 trên máy chủ mail bằng cách chạy TCPing.exe vào vai trò Azure qua RDP.