【发布时间】:2021-02-03 11:56:41
【问题描述】:
我正在尝试使用 python 发送电子邮件,因为我必须批量发送许多电子邮件并且希望使用 python 这样做。我写的代码如下。但是,当我运行它时,出现以下错误
TimeoutError: [WinError 10060] 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应
我认为这可能是 Outlook 中的设置问题,但我不确定。
import smtplib
with smtplib.SMTP('smtp.outlook365.com',587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login('email@address.com','password')
subject = 'This is a test.'
body = 'wonder if this works!'
msg = f'Subject: {subject}\n\n{body}'
smtp.sendmail('sender@email.com','receiver@email.com',msg)
【问题讨论】:
标签: python connection office365