Cannot send email from EC2 instance on port 587
Solution 1
For send an email from AWS EC2 using Gmail SMTP service please follow below steps.
- Edit security group of your EC2 Instance.
- Edit inbound rules of the security group.
- Add 587 port in inbound rules. See below image.
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
Solution 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
Related videos on Youtube
Tahsin Mostafiz
Updated on September 18, 2022Comments
-
Tahsin Mostafiz over 1 year
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.
-
bahamat over 10 yearsYou might consider using Amazon SES instead.
-
Philip over 10 yearsYour server is reachable other than the e-mail not working? Like, can you ping a gmail server?
-