简体   繁体   English

AWS 私有子网 EC2 上的 SMTP,网络无法访问 [errorno 101]

[英]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

  • do you have a NAT gateway in the private subnet where your smtp is located?您的 smtp 所在的私有子网中是否有 NAT 网关?
  • 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还要检查公共子网中的 ACL 规则
  • security group attached to the server, is it open?附加到服务器的安全组,它是否打开?

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.

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