首页 > 解决方案 > 如何绕过网络导致的 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)

标签: pythonemailnetworkingsmtp

解决方案


推荐阅读