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

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.


I have fixed issue as of now for a development server. Please, not it's not the correct way to a production site.

For sending an email from AWS EC2 using Gmail SMTP service please follow below steps.

  1. Edit security group of your EC2 Instance.
  2. Edit inbound rules of the security group.
  3. Add 587 port in inbound rules. See below image.

you need to set your instance inbound rules for coming mail and outbound for send.

enter image description here

After that, you can send email using 587 SMTP port from AWS EC2.

Please read this article. https://support.google.com/accounts/answer/6010255?hl=en

https://myaccount.google.com/lesssecureapps