我想通过python发送电子邮件,我按照this中的以下代码进行操作链接:
import smtplib
mailserver = smtplib.SMTP('smtp.office365.com',587)
mailserver.ehlo()
mailserver.starttls()
mailserver.login('myemail@company.com', 'mypassword')
msg = ('this is a message')
mailserver.sendmail('myemail@company.com','receiver@company.com',msg)
问题: 该电子邮件位于我的发件箱和收件人的收件箱中,但没有文本。它是空的。
没有错误或输出,脚本只是运行,所以我不确定从哪里开始排除故障,因为我不是这方面的专家;谁能解释一下为什么没有消息/文本?
最佳答案
您需要在 sendmail
的第三个参数中的主题和电子邮件正文之间添加 \n
msg = 'Subject: Email Subject.\n{}'.format('this is a message')
mailserver.sendmail('myemail@company.com','receiver@company.com', msg)
关于python - Office365 的 SMTP 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56294982/