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