使用Python中的Yagmail从Outlook365发送电子邮件(允许SMTP访问)

2024-06-06 23:26:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以使用Python中的Yagmail模块通过Gmail帐户发送电子邮件,但当我尝试使用Outlook电子邮件地址时,我会得到一个SMTPAuthenticationError。在

Gmail要求我允许“不太安全的应用程序”访问我的帐户,但我在Outlook365上找不到这样的选项。在

这是我使用Yagmail的Gmail代码:

import keyring
keyring.set_password('yagmail', 'user@gmail.com', 'mypassword')

import yagmail
FROM = "user@gmail.com"
TO = "other@email.com"
SUBJECT = "test email"
TEXT = "details go here"

yagmail.SMTP(FROM).send(TO, SUBJECT, TEXT)

Tags: totextfromimportcom电子邮件email帐户
1条回答
网友
1楼 · 发布于 2024-06-06 23:26:17

我用以下方法让它工作:

import yagmail
FROM = 'user@gmail.com'
TO = 'other@email.com'
SUBJECT = 'test email'
TEXT = 'details go here'

yag = yagmail.SMTP('myO365email.com', 'myO365pw', host='smtp.office365.com', port=587, smtp_starttls=True, smtp_ssl=False)
yag.send(TO, SUBJECT, TEXT)

窍门是配置smtptls/SSL选项。在

相关问题 更多 >