# 导入 smtplib 和 MIMETextimport smtplibfrom email.mime.text import MIMEText # 定义发送列表mailto_list=["root@pythontab.com","10118157@qq.com"] # 设置服务器名称、用户名、密码以及邮件后缀mail_host = "smtp.163.com"mail_user = "xx@163.com"mail_pass = "xx"mail_postfix="163.com" # 发送邮件函数def send_mail(to_list, sub, context): ''''' to_list: 发送给谁 sub: 主题 context: 内容 send_mail("xxx@126.com","sub","context") ''' me = mail_user + "" 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","你好")
登录后复制
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2284310.html