【发布时间】:2019-07-06 22:29:04
【问题描述】:
我正在尝试创建一个 python 脚本来发送带有一些消息的电子邮件。 我的设置基于 smtp.office365.com。我创建了一些脚本来完成这项工作。
#!/usr/bin/python
print ("HI! let's start")
import smtplib
import getpass
port=587
smtp_server="smtp.office365.com"
sender_email='mymail@something.com'
receiver_email='mymail@something.com'
print ("defining server")
server = smtplib.SMTP(smtp_server,port)
password=getpass.getpass("enter password")
message='''
Hi,
THIS IS A TEST MESSAGE.
'''
print ("logging in")
server.login(sender_email,password)
print ("sending mail now")
server_sendmail(sender_email,receiver_email,message)
print ("all must be done by now")
但由于某些原因,打印“定义服务器”后卡住了。并且永远不会要求输入密码。显然 smtplib.SMTP 命令挂起。你能说出为什么会发生这种情况以及如何摆脱它吗?我的设置如下:
Server: smtp.office365.com
/sjmail.com
security : STARTTLS
Port : 587
【问题讨论】:
-
请看这个关于如何使用 TLS 的答案:stackoverflow.com/a/58997830/1810962。你错过了
server.starttls(context=context)
标签: python-2.7 smtp smtplib