有图有真相
代码
1、mail.py
#-*-coding:utf-8-*-
#!/bin/pyton
import sys
import smtplib
import logging
from email.mime.text import MIMEText
def send_mail(to_list, cc_list, html, sub):
me = mail_user
msg = MIMEText(html, _subtype='html', _charset='utf-8') # 格式化邮件内容为html,编码为utf-8
msg['Subject'] = sub # 邮件主题
msg['From'] = me # 发件人
msg['To'] = ";".join(to_list) # 收件人,将列表转换为字符串
msg['Cc'] = ";".join(cc_list) # 抄送人,将列表转换为字符串
try:
send_smtp = smtplib.SMTP() # 实例化
send_smtp.connect(mail_host) # 连接smtp服务器
send_smtp.login(mail_user, mail_pass) # 使用定义的账号密码进行登录
send_smtp.sendmail(me, to_list+cc_list, msg.as_string()) # 发送邮件