简体   繁体   中英

SMTP on AWS private subnet EC2, Network unreachable [errorno 101]

Trying to send emails using SMTPlib in python script on private subnet EC2 machine using following code. EC2 machine has communication with internal SMTP server through PORT 25 , verified using telnet command. This code works fine from public subnet EC2 but throws error mentioned at the bottom on private subnet.

import smtplib
from email.MIMEMultipart import MIMEMultipart  #python 2


msg = MIMEMultipart()
msg['From'] = 'myid@domain.com'
msg['To'] = 'youid@domain.com'
msg['Subject'] = 'simple email in python'
message = 'here is the email'


mailserver = smtplib.SMTP('smtp.gmail.com',25)

mailserver.ehlo()

mailserver.starttls()

mailserver.ehlo()
mailserver.login('myid@domain.com', 'password')

mailserver.sendmail('myid@domain.com','youid@domain.com',msg.as_string())

mailserver.quit()

Getting this error socket.error: errorno[101] - Network is unreachable

  • do you have a NAT gateway in the private subnet where your smtp is located?
  • do you have active access control layer on that private subnet where your server is located? Is it blocking anything?
  • also check ACL rules in public subnet
  • security group attached to the server, is it open?

Email server configuration was wrong and the email server did not require login.

mailserver = smtplib.SMTP(internal office server,25)


#mailserver.login('myid@domain.com', 'password') -- Not required for the server

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM