-1

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

2 Answers2

0
  • 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?
Tomek Klas
  • 722
  • 5
  • 6
0

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.