6

I have written a mail service for our flask application that uses Celery and RabbitMQ to send emails (using gmail). I have got the celery consumer and producer communicating okay but I cannot get to send send emails. I am getting a socket.error: [Errno 101] Network is unreachable.

I think this means that AWS is blocking port 587 - even though in my security group I opened both ports 587 and 25 (inbound and outbound).

Any reason why this is happening? Any help will be highly appreciated.

Tahsin Mostafiz
  • 61
  • 1
  • 1
  • 2

3 Answers3

4

For send 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.

enter image description here

you need to set your instance inbound rules

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
  • 141
  • 2
2

if the aws firewall wrapper is denying tcp/587 to the world, it can be opened using the ec2 api tools:

ec2-authorize [sec-group-id] -P tcp -p 587 -s 0.0.0.0/0

although it sounds like you have already opened this. to verify, run

ec2-describe-group [sec-group-id]

regarding icmp not responding, you can open that up by:

ec2-authorize [sec-group-id] -P icmp -t -1:-1 -s [your-public-ip]/32

nandoP
  • 2,021
  • 14
  • 15
0

It took me a while to figure out, but Amazon blocks the port 25 (SMTP) on EC2 instances and it's not clear whether or not it blocks all outbound emails as well : https://aws.amazon.com/premiumsupport/knowledge-center/ec2-port-25-throttle/?nc1=h_ls

You need to request an email sending limitation removal : https://support.console.aws.amazon.com/support/contacts#/rdns-limits