Question

I am trying to connect to an amazon server for sending emails by editing by web.config

  <system.net>
   <mailSettings>
    <smtp deliveryMethod="Network">
     <network enableSsl="true" port="587" host="email-smtp.us-east-1.amazonaws.com" password="actual password" userName="actual username"/>
    </smtp>
   </mailSettings>
  </system.net>

These settings are being set as evidenced below: enter image description here

All I am doing in code is

SmtpClient client = new SmtpClient();
client.SendCompleted += SendCompletedCallback;
string userState = _id.ToString();
client.SendAsync(msg, userState);

but the error I get back is always

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 184.73.222.29:587

Before I was using an internal mail server, but since this will be getting pushed to the amazon cloud, I will not have access to the local server. In the case of the local server, all i had to do was specify the ip address for host and it ran just fine.

Was it helpful?

Solution

There were three issues at hand:

1: The email address it was being sent from was not verified with Amazon, and neither was the recipient (verification of recipient only needed in sandbox mode)

2: The out port I was using, 587, is blocked by my company, which seems to be common practice

3: Using async can only be done when you specify the page uses async in the aspx "header"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top