python - 如何绕过网络导致的 SMTP 超时?
问题描述
我正在尝试使用附带的 python 程序发送电子邮件。在此我使用smtp 服务器,当我尝试使用我的移动数据连接时代码工作正常,但当我尝试在我的大学 wifi 网络中时失败。即使我已经尝试了以下所有端口号 25,465,587,2525 和 2526 ,但仍然无法正常工作。所以建议一种在这样的网络或 python 或 C++ 中的其他相关来源中发送电子邮件的方法。
# Python 3
import smtplib
port_number = 587 # 25
def send_Mail(src,des,password,message):
global port_number
try:
print("Start")
server = smtplib.SMTP('smtp.gmail.com',port_number) # Failing in this line
print("Connection Established")
server.ehlo()
print("Extended hello done")
server.starttls()
print("tls Handshake completed")
server.login(src,password)
print("Logged in")
server.sendmail(src,des,message)
print("Mail sent")
server.quit()
print("Success!")
except:
pass
mail_of_sender = "example@example.com"
recipient_mail_id = "test@example.com"
password = "testingpassword"
message = "Testing"
send_Mail(mail_of_sender,recipient_mail_id,password,message)
解决方案
推荐阅读
- php - 创建自定义配置文件 url 导航项 buddypress
- c# - Azure 容器中的 WorkerService TCPListener
- git - 在 GitLab 中自动下载资源
- java - 使用相同名称多次定义和应用 Gradle 任务
- swift - UITableViewCell 未覆盖 tvOS ContainerView 中 UITableView 的全帧
- javascript - Amcharts - 如何删除网格线但保留基本 x 和 y 轴
- php - 未捕获的错误:调用成员函数查询
- dataframe - PySpark数据框写入orc不允许带有连字符的列名
- python - pd.categorical 没有按情节中的指定顺序对条形图进行排序
- python - 从 http 请求响应中提取 JSON - Scrapy