我正在尝试通过office365服务器发送电子邮件。电子邮件已正确发送,但未附加邮件

协助深表感谢

import smtplib

to = "[email protected]"
office365_user = '[email protected]'
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: <[email protected]>
To: <[email protected]>
Subject: foo

This is a test email
"""

10-07 22:25