【发布时间】:2016-12-20 10:07:39
【问题描述】:
我正在尝试用 Python 发送电子邮件
使用此代码使用 gmail 可以正常工作:
import smtplib
sender = 'xxx@xxx'
receivers = ['xxx@gmail.com']
message = "hello"
try:
smtpObj = smtplib.SMTP('smtp.gmail.com:587')
smtpObj.starttls()
smtpObj.login('xxxx@gmail.com', 'my_password')
smtpObj.sendmail(sender, receivers, message)
smtpObj.quit()
print("okay")
except:
print("notokay")
但是当我在office 365上使用它时,电子邮件已发送但消息为空。
代码相同,但 'smtp.office365.com:587' 使用正确的登录名和密码。
【问题讨论】: