Airflow发邮件smtplib实例

import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from airflow import configuration as conf

#从airflow.cfg中获取自己配置的发送邮箱地址
sender_mail = conf.get("smtp", "smtp_mail_from")
mail_host = conf.get("smtp", "smtp_host")
message = MIMEMultipart()
message['From'] = sender_mail
# 收件人
to_list = ['[email protected]', '[email protected]']
message['To'] = ";".join(to_list)
# 邮件主题
subject = "Text not sent on time"
message['Subject'] = Header(subject)
# 邮件正文
body = "测试!"
message.attach(MIMEText(body, 'plain', 'utf-8'))
smtp_obj = smtplib.SMTP(mail_host)
smtp_obj.sendmail(sender_mail, to_list, message.as_string())

 

你可能感兴趣的:(AIRFLOW)