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'] = '[email protected]'
msg['To'] = '[email protected]'
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('[email protected]', 'password')
mailserver.sendmail('[email protected]','[email protected]',msg.as_string())
mailserver.quit()
Getting this error socket.error: errorno[101] - Network is unreachable