11

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.

Krupal Patel
  • 1,387
  • 3
  • 12
  • 28
  • It is unclear what you are actually trying to accomplish here. Are you trying to **send** email from EC2 using GMail credentials? If that is not working, then how exactly does it fail? Or are you trying to set up your server to accept incoming mail? – Michael - sqlbot Jul 11 '17 at 17:01
  • 1
    I'm trying to send email from EC2 using Gmail credentials and I used 587 port for Gmail SMTP. But AWS EC2 is allowed only 25 SMTP port. Now as per Google documents Gmail does not offer port 25 in an unsecured connection. So there is any other way to use 587 SMTP port on AWS EC2 – Krupal Patel Jul 12 '17 at 05:19

4 Answers4

13

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

Krupal Patel
  • 1,387
  • 3
  • 12
  • 28
  • 2
    it looks strange because inbound means "comming in" but sending is rather "comming out" which does not restrict by default. Does it means that you have installed software which listen 587 port? – Ruslan Neruka Jul 13 '17 at 14:23
  • 3
    I updated as shown, but still mails are not going out – Krishna Vedula Aug 14 '17 at 10:23
  • Tried this but it isn't working. @Krupal Patel, could you please update you answer with the proper way around for sending email. – Omer Waqas Khan Jun 26 '21 at 08:37
4

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.

Sunil Kothiyal
  • 157
  • 1
  • 12
2

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.
Amit Sharma
  • 133
  • 8
1

According to Googles documentation, you can use the G Suite SMTP relay service through port 25. You can read more information here:

https://support.google.com/a/answer/176600?hl=en

and here:

https://support.google.com/a/answer/2956491

Hope this helps!

Jesse Hogue
  • 107
  • 4
  • 1
    Gmail does not offer port 25 in an unsecured connection. For use port 25 secure connection are required as per gmail "Configuration requirements" https://support.google.com/a/answer/176600?hl=en – Krupal Patel Jul 13 '17 at 07:24