System.Net.Mail.SmtpException套接字以其访问权限禁止的方式

时间:2020-09-01 02:46:16

标签: c# asp.net asp.net-core azure-web-app-service smtpclient

我正在尝试使用SmtpClient在具有内部(非天蓝色)电子邮件服务器的天蓝色Web服务中发送电子邮件,以发送电子邮件。我们使用混合连接进入内部网络。

 var client = new SmtpClient()
            {
                Port = model.Port,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Host = model.Host,
                EnableSsl = true,
                Credentials = new NetworkCredential(model.UserName, model.Password)
            };
            await client.SendMailAsync(mail);

在发送电子邮件时遇到异常。

System.Net.Mail.SmtpException: Failure sending mail.
 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions. [::ffff:xxxx.xx.xxx.xxx]:xx
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
   at System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context)
   at System.Net.Sockets.Socket.DnsCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
   at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.InitializeConnectionCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
   at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
   at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
   --- End of inner exception stack trace ---
   at Monash.Identity.DomainLogic.Commands.Handlers.Account.GenerateBackupCodesEmailHandler.ExecuteAsync(GenerateBackupCodesEmailCommand command) in D:\a\1\s\src\Monash.Identity.DomainLogic\Commands\Handlers\Account\GenerateBackupCodesEmailHandler.cs:line 36
   at Monash.Identity.DomainLogic.Commands.CommandHandlerBase`2.HandleAsync(TCommand command) in D:\a\1\s\src\Monash.Identity.DomainLogic\Commands\CommandHandlerBase.cs:line 28

0 个答案:

没有答案