【问题标题】:How do I resolve a connection error when sending an email through outlook with python?使用python通过outlook发送电子邮件时如何解决连接错误?
【发布时间】: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


    【解决方案1】:

    查看smtp服务器的地址,参考微软文档我看到地址不一样。

    SMTP 服务器名称 smtp.office365.com

    https://support.microsoft.com/en-us/office/pop-imap-and-smtp-settings-for-outlook-com-d088b986-291d-42b8-9564-9c414e2aa040

    【讨论】:

    • 好的,成功了。虽然现在我收到一个身份验证错误。关于那里可能发生的事情有什么想法吗?
    猜你喜欢
    • 2011-09-14
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多