1 def send_mail(to_list,sub,content): 2 me="MBD-data"+"<"+mail_user+"@"+mail_postfix+">" 3 msg = MIMEText(content,_subtype='plain',_charset='utf-8') 4 msg['Subject'] = sub 5 msg['From'] = me 6 msg['To'] = ";".join(to_list) 7 try: 8 server = smtplib.SMTP() 9 server.connect(mail_host) 10 server.login(mail_user,mail_pass) 11 server.sendmail(me, to_list, msg.as_string()) 12 server.close() 13 return True 14 except Exception, e: 15 print time.strftime('%Y-%m-%d', time.localtime(time.time())) + " : "+ str(e) 16 return False
mail_user 发件人用户名
mail_postfix 发件邮箱域名
sub 邮件主题
content 邮件内容
to_list 收件人列表
mail_host smtp服务器域名
mail_pass 发件人密码
需要
import smtplib,time
from email.mime.text import MIMEText