如何在 python 中使用 smtp 连接到正确的 smtp 服务器以发送电子邮件

How to connect to the correct smtp server for sending email using smtp in python

提问人:AJS 提问时间:10/17/2023 更新时间:10/17/2023 访问量:46

问:

我正在为客户工作,我必须使用 SMTP 在 Outlook 中从我的工作电子邮件 ID ([email protected]) 发送带有附件的邮件。

我使用 smtp.outlook.com 作为服务器,它不起作用,那么如何找到域的正确服务器呢?

服务器=?

with smtplib.SMTP(SERVER, 587) as server:

    server.starttls()
    print("connected to server")
    server.login(user, PASS)
    server.sendmail(FROM, TO, text)
python 电子邮件 smtplib

评论

1赞 stdunbar 10/17/2023
您需要有一个帐户或权限才能通过 SMTP 发送 - 开放中继的日子早已一去不复返了。您有 outlook.com 账户吗?你看过这样的帖子吗?在这种情况下,“不起作用”是什么意思?
0赞 AJS 10/17/2023
嗨,stdunbar,我在Outlook中有一个帐户,例如: [EMAIL PROTECTED] 。任务是向我的公司网络发送邮件,例如:[email protected]。但我不确定我必须使用什么服务器。当我尝试 smtp-mail.outlook.com 时。代码运行了很长时间。所以我不知道我是否使用正确的SMTP服务器进行连接
0赞 stdunbar 10/18/2023
根据一些简单的搜索,您应该使用 .smtp-mail.outlook.com

答: 暂无答案