[英]python: smtp with TLS delivers no message
我正在嘗試通過office365服務器發送電子郵件。 電子郵件已正確發送,但未附加郵件
協助深表感謝
import smtplib
to = "me@gmail.com"
office365_user = 'announcement@somewhere.com'
office365_pwd = 'password'
smtpserver = smtplib.SMTP("smtp.office365.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login(office365_user,office365_pwd)
msg = "This is a test email \n"
smtpserver.sendmail(office365_user, to, msg)
smtpserver.close()
您的郵件不是有效的郵件,它由標題和正文組成。 嘗試這樣的事情:
msg = """From: <me@example.com>
To: <you@example.com>
Subject: foo
This is a test email
"""
考慮以與Python文檔相同的方式構造消息。
from email.mime.text import MIMEText
msg = MIMEText("This is a test email")
msg['Subject'] = 'Email Subject'
msg['From'] = 'announcement@somewhere.com'
msg['To'] = 'me@gmail.com'
另外,我不確定要使用smtpserver.close()
。 似乎正確的方法是smtpserver.quit()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.