0

Same ASP.NET MVC 4 website, same mail send code. Sending e-mail messages from AccountController is not working anymore, from all the other controllers it is.

Here is the error I get from AccountController actions:

Cannot send e-mail from noreply@domain.com to bill@microsoft.com
Exception: Mailbox unavailable. The server response was: 5.7.1 Unable to relay.
mail.domain.com, SMTPSVC/mail.domain.com, 25, 

What should I check? It worked from years but with a recent Windows Server 2008 / Exchange 2010 update is not working anymore.

MailMessage message = new MailMessage(fromAddress, toAddress)
{
   Subject = subject,
   Body = body,
   IsBodyHtml = isHtml
};

try
{
   smtpClient.Send(message);

   string errorMsg = "Sending e-mail from " + fromAddress.Address + " to " + originalAddresses[i];
   errorMsg += Environment.NewLine;
   errorMsg += smtpClient.Host + ", " + smtpClient.TargetName + ", " + smtpClient.Port + ", " + smtpClient.ClientCertificates + ", " + smtpClient.EnableSsl + ", " + smtpClient.UseDefaultCredentials + ", " + smtpClient.Timeout;

   sw.WriteLine(errorMsg)
}
catch (Exception ex)
{
   string errorMsg = "Cannot send e-mail from " + fromAddress.Address + " to " + originalAddresses[i] + ", " + "Exception: " + ex.Message +
                                (ex.InnerException != null ? ", " + ex.InnerException.Message : string.Empty);
   errorMsg += Environment.NewLine;
   errorMsg += smtpClient.Host + ", " + smtpClient.TargetName + ", " + smtpClient.Port + ", " + smtpClient.ClientCertificates + ", " + smtpClient.EnableSsl + ", " + smtpClient.UseDefaultCredentials + ", " + smtpClient.Timeout;

   sw.WriteLine(errorMsg);

   return false;
}

Any idea of what should I check? Has AccountController something special I should care about? Is the [RequireHttps] controller action attribute somewhat involved?

Thanks.

EDIT1:

Here are our Exchange 2010 settings (please note that we can send the same e-mail message from other ASP.NET MVC controllers):

https://practical365.com/exchange-server/how-to-configure-a-relay-connector-for-exchange-server-2010/

EDIT2:

I was wrong, the problem is not ASP.NET MVC controller related but e-mail address domain related. I discovered that the all the times we include an e-mail address that doesn't belong to our company domain (the outer internet) we get the error above. So now the question is: why the Exchange 2010 Receive Connector is now unable to send e-mail notification to the outer internet?

abenci
  • 8,422
  • 19
  • 69
  • 134
  • 1
    Isn't it just that you may need to authenticate with the SMTP server? Since you are trying to send a mail to a different domain (domain.com != microsoft.com) ? – kayess Jun 21 '17 at 08:12
  • Check relay restriction settings on IIS Manager => Default SMTP Virtual Server => Properties => Access => Relay Restrictions, add your public IP address there, then mark anonymous access & Integrated Windows Authentication in authentication access control setting. Also check existing `NetworkCredential` used to send the mail. – Tetsuya Yamamoto Jun 21 '17 at 08:13
  • @kayess: we do, in fact from all other controllers the e-mail are sent and delivered. – abenci Jun 21 '17 at 08:29
  • @Tetsuya: We don't use a virtual server but a Exchange 2010 Receive Connector (see my edit). – abenci Jun 21 '17 at 08:29
  • Since you're stated using Exchange server, and sending mail to different host said `domain.com`, it may require credential setting depends on `mail.domain.com` as target domain. Check http://practical365.com/how-to-add-remote-ip-addresses-to-existing-receive-connectors & https://stackoverflow.com/questions/15717743/mailbox-unavailable-the-server-response-was-5-7-1-unable-to-relay-error. – Tetsuya Yamamoto Jun 21 '17 at 08:38

1 Answers1

0

The server farm changed the outgoing IP address of our server and this was blocking all e-mail messages that contain a recipient not in our company domain. Adding the new outgoing IP address to the Exchange 2010 Receive Connector under Properties->Network->Receive mail from remote servers that have these IP addresses solved the problem.

abenci
  • 8,422
  • 19
  • 69
  • 134