我正在编写一个小的 python 脚本来发送电子邮件,但我的代码甚至无法通过 smtp 连接。我正在使用以下代码,但我从未看到“已连接”。此外,我没有看到抛出异常,所以我认为它挂在某些东西上。
import os
import platform
import smtplib
#Define our SMTP server. We use gmail. Try to connect.
try:
server = smtplib.SMTP()
print "Defined server"
server.connect("smtp.gmail.com",465)
print "Connected"
server.ehlo()
server.starttls()
server.ehlo()
print "Complete Initiation"
except Exception, R:
print R
Run Code Online (Sandbox Code Playgroud)