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

标签 python python-2.7 email outlook yagmail

我可以使用 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)

最佳答案

我使用以下方法让它工作:

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)

诀窍是配置 SMTP TLS/SSL 选项。

关于python - 在 Python 中使用 Yagmail 从 Outlook365 发送电子邮件(允许 SMTP 访问),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42005339/

相关文章:

python-2.7 - Azure 中没有用于 Ansible VM 预配的名为 Packaging.version 的模块

python - 从多个系列创建 DataFrame

没有 JavaMail API 的 Java POP3 消息解析器

python - 'numpy.reshape' 和 'ndarray.reshape' 如何等效?

Python pandas groupby 有条件地将字符串连接成多列

python - 类型错误 : 'datetime.datetime' object is not iterable

python - 带有值检查的生成器表达式

python - 谷歌应用引擎 Python Cron

c# - 如何通过 Yandex SMTP 发送电子邮件 (C# ASP.NET)

python - 反转查询集/列表,然后切片