美文网首页
Python3 发送outlook邮件

Python3 发送outlook邮件

作者: 我是非鱼 | 来源:发表于2019-10-09 09:49 被阅读0次
import smtplib
from email.mime.text import MIMEText  # 引入smtplib和MIMEText

def send_email(self, to, subject, template):

        mailserver = smtplib.SMTP('smtp.office365.com', 587)
        msg = MIMEText(template, 'html')  # 设置正文为符合邮件格式的HTML内容
        msg['subject'] = subject  # 设置邮件标题
        msg['from'] = self.app.config['MAIL_DEFAULT_SENDER']  # 设置发送人
        msg['to'] = to  # 设置接收人

        mailserver.ehlo()
        mailserver.starttls()
        mailserver.login(self.app.config['MAIL_DEFAULT_SENDER'], self.app.config['MAIL_PASSWORD'])
        mailserver.sendmail(self.app.config['MAIL_DEFAULT_SENDER'], to, msg.as_string())
        mailserver.quit()

相关文章

网友评论

      本文标题:Python3 发送outlook邮件

      本文链接:https://www.haomeiwen.com/subject/diywpctx.html