How do I use Gmail SMTP with port 587 on AWS EC2?

Viewed 27697

I have used Gmail SMTP service with port 587 on the local server and it's working fine.

But it's not working on AWS EC2 instance. So I added SMTP rules on EC2 instance security inbound rules see below image but SMTP port can not be editable.

Now the issue is if your domain does not configureenter image description here secured connections. Gmail does not offer port 25 in an unsecured connection.

So, there is any way to use SMTP on unsecured connection with 25 port or any other way.

4 Answers

Because of the spam abuse that has historically been sent from people using EC2 instances, virtually ALL popular mail providers block the receipt of email from EC2 instances. The world of email and anti-spam measures is part-technical, part-political. For this reason, AWS offers Amazon Simple Email Service.

Step to fix it-

  1. Go to google account setting and Turn on Two-step verification.
  2. Now generate an app password for the app you want to send mail.
  3. Use the generated password for the app in SMTP with the same Email.

That's it.

To send email from C# hosted on Amazon EC2, make sure you have two things done.

  1. Use following setting in your Web.config
<mailSettings>
      <smtp deliveryMethod="Network" from="<from email goes here>">
        <network host="smtp.gmail.com" port="587" enableSsl="true" userName="email id goes here" password="<password goes here> />   
      </smtp>
    </mailSettings>
  1. Login the above gmail account onto the Amazon EC2. If you do not login, then gmail blocks the email being sent from code due to security reasons.
Related