當我在 jupyter 中運行代碼時正在接收郵件,但是我通過 python 在我的 Linux 機器中嘗試沒有收到任何郵件。
這是下面的代碼:
#! /usr/bin/python
import smtplib
import ssl
port = 587
smtp_server = "smtp-mail.outlook.com"
sender = "[email protected]"
recipient = "[email protected]"
sender_password = "Password"
message = """
Subject: This is a test message
Sent using Python."""
SSL_context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.starttls(context=SSL_context)
server.login(sender, sender_password)
server.sendmail(sender, recipient, message)
uj5u.com熱心網友回復:
您正在嘗試使用 SMTP 連接 Outlook。您應該要求您的電子郵件帳戶允許 smtp,默認情況下不一定啟用。
此外,您可以嘗試基于庫的其他解決方案;
from O365 import Message
html_template = """
<html>
<head>
<title></title>
</head>
<body>
{}
</body>
</html>
"""
final_html_data = html_template.format(df.to_html(index=False))
o365_auth = ('sender_username@company_email.com','Password')
m = Message(auth=o365_auth)
m.setRecipients('receiver_username@company_email.com')
m.setSubject('Weekly report')
m.setBodyHTML(final)
m.sendMessage()
來自https://stackoverflow.com/a/52534847/5942941
或安裝 redmail:
pip install redmail
并嘗試使用此示例;
from redmail import outlook
outlook.user_name = "[email protected]"
outlook.password = "<MY PASSWORD>"
outlook.send(
receivers=["[email protected]"],
subject="An example",
text="Hi, this is an example."
)
https://stackoverflow.com/a/71056577/5942941
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/484804.html
上一篇:MySQL電子郵件過濾
