[英]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 机器上的 python 脚本中使用 SMTPlib 发送电子邮件。 EC2 machine has communication with internal SMTP server through PORT 25
, verified using telnet
command. EC2 机器通过PORT 25
与内部 SMTP 服务器通信,使用telnet
命令验证。 This code works fine from public subnet EC2 but throws error mentioned at the bottom on private subnet.此代码在公共子网 EC2 中运行良好,但在私有子网底部引发错误。
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
收到此错误socket.error: errorno[101] - Network is unreachable
Email server configuration was wrong and the email server did not require login. Email 服务器配置错误,email 服务器不需要登录。
mailserver = smtplib.SMTP(internal office server,25)
#mailserver.login('myid@domain.com', 'password') -- Not required for the server
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.