mfo27
mfo27

Reputation: 63

Python SMTP - [Errno 101] Network is unreachable on AWS EC2

I am trying to verify the email address of the user.

When trying to connect to the user's host using MX record I always get a 'Network is unreachable' error on the AWS EC2 instance. However, it works perfectly fine locally.

records = dns.resolver.query(domain, 'MX')
mx_record = records[0].exchange
mx = str(mx_record)
smtp_server = smtplib.SMTP(host=mx)

If I try to use:

smtp_server = smtplib.SMTP_SSL(host=mx, port=465)

I get the same issue.

Please share any ideas. Thanks!

Upvotes: 2

Views: 2157

Answers (1)

Marcin
Marcin

Reputation: 238837

It does not work probably because:

AWS blocks outbound traffic on port 25 (SMTP) of all EC2 instances and Lambda functions by default. If you want to send outbound traffic on port 25, you can request for this restriction to be removed.

Although not explicitly stated I would say it is same for 465.

As explained in the link, you have to contact AWS support to remove this restriction, or use AWS SES.

Upvotes: 1

Related Questions