现在的位置: 主页 > 公司荣誉 > 文章列表

python 邮件发送模板

作者:沈阳市沈河区金瑞龙美术社 来源:www.jrlgg.com 发布时间:2017-09-05 12:13:14
 

python 邮件发送模板

文本内容:

#!/usr/bin/env python # -*- coding=utf-8 -*- import smtplib from email.mime.text import MIMEText def send_mail(to_list,sub,content): mail_host = "***" # 设置服务器 mail_user = "***" # 用户名 mail_pass = "***" # 口令 mail_postfix = "***" # 发件箱的后缀 mail_port = *** # 端口 sender="Alerter"+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content,_subtype='plain',_charset='utf-8') msg['Subject'] = sub msg['From'] = sender msg['To'] = ";".join(to_list) try: server = smtplib.SMTP() server.connect(mail_host, mail_port) server.login(mail_user, mail_pass) server.sendmail(sender, to_list, msg.as_string()) server.close() return True except Exception, e: print str(e) return False if __name__ == '__main__': subject='text_test' send_content = '' mailto_list=['***@163.com',...] send_mail(mailto_list, subject, send_content)

html 内容:

def send_mail(to_list,sub,content): mail_host = "***" # 设置服务器 mail_user = "***" # 用户名 mail_pass = "***" # 口令 mail_postfix = "***" # 发件箱的后缀 mail_port = *** # 端口 sender="Alerter"+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content,_subtype='html',_charset='utf-8') msg['Subject'] = sub msg['From'] = sender msg['To'] = ";".join(to_list) try: server = smtplib.SMTP() server.connect(mail_host, mail_port) server.login(mail_user, mail_pass) server.sendmail(sender, to_list, msg.as_string()) server.close() return True except Exception, e: print str(e) return False

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:武汉网站建设 http://wuhan.45qun.com

  • 上一篇:软文新发布渠道解析
  • 下一篇:最后一页
  •