Отправка электронной почты Amazon SES SMTP работает нормально с PowerShell, но не с кодом asp. net - PullRequest
0 голосов
/ 19 марта 2020

Отправка нашей электронной почты с использованием AWS SMTP работает нормально с кодом оболочки ниже power Но теперь asp. net Код

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
$EmailFrom = "tester@test.com"
$EmailTo = "test@itest.in"
$Subject = "Test email sent from Amazon SES"
$Body = "This message was sent from Amazon SES using Windows PowerShell."
$SMTPServer = "email-swestnorth.amazonaws.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("testuser", "<password>");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Remove-Variable -Name SMTPClient

Наш ASP. NET Код, который не работает нормально

static SmtpClient mSmtpClient = null;
static NetworkCredential mNetworkCredential = null;
MailMessage message = null;

message = new MailMessage()
{
    Body = notification.Body,
    From = notification.From,
    IsBodyHtml = notification.IsBodyHTML,
    Subject = notification.Header
};
PrepareTo(notification.To, message);
PrepareCC(notification.CC, message);
PrepareBcc(notification.BCC, message);
PrepareAttachments(notification.Attachment, message);
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
mSmtpClient.Send(message);

ОШИБКА для этой операции с использованием ASP. NET SMTP-классов

Mail Sending Failed System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'email-smtp.us-east-l.amazonaws.com'
   at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
   at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
   at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   --- End of inner exception stack trace ---
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
...