smtplib模块发送邮件
2018-07-20 来源:open-open
# 导入 smtplib 和 MIMEText import smtplib from email.mime.text import MIMEText # 定义发送列表 mailto_list=["root@pythonpy.com","505249727@qq.com"] # 设置服务器名称、用户名、密码以及邮件后缀 mail_host = "smtp.qq.com" mail_user = "xx@qq.com" mail_pass = "xx" mail_postfix="qq.com" # 发送邮件函数 def send_mail(to_list, sub, context): ''''' to_list: 发送给谁 sub: 主题 context: 内容 send_mail("xxx@qq.com","sub","context") ''' me = mail_user + "<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(context) msg['Subject'] = 'python email test' msg['From'] = sub msg['To'] = ";".join(to_list) try: send_smtp = smtplib.SMTP() send_smtp.connect(mail_host) send_smtp.login(mail_user, mail_pass) send_smtp.sendmail(me, to_list, msg.as_string()) send_smtp.close() print 'success' return True except (Exception, e): print(str(e)) print 'false' send_mail(mailto_list,"test mail","你好,坤子的blog 测试邮件")
标签: 服务器
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:C#通过设置注册表实现文件关联
下一篇:PHP发送电子邮件代码
最新资讯
热门推荐