我正在尝试通过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()
您的邮件不是由标头和正文组成的有效邮件。试试这样的方法:
考虑用与Python documentation相同的方式构造消息。在
另外,我不确定是否使用
smtpserver.close()
。似乎正确的方法是smtpserver.quit()
。在相关问题 更多 >
编程相关推荐