首页 > 代码库 > Python发邮件的小脚本
Python发邮件的小脚本
1 # -*- coding: UTF-8 -*- 2 import smtplib 3 from email.mime.text import MIMEText 4 5 mailto_list = [‘hitwh_Gypsy@126.com‘,‘hitwh_Gypsy@163.com‘,‘hitwh_Gypsy@aliyun.com‘,‘1027179157@qq.com‘] 6 mail_host = "smtp.qq.com" # 设置服务器 7 mail_user = "1027179157" # 用户名 8 mail_pass = "xxxxxxxxx" # 口令 9 mail_postfix = "qq.com" # 发件箱的后缀10 11 def send_mail(to_list, sub, content):12 me = "hello" + "<" + mail_user + "@" + mail_postfix + ">"13 msg = MIMEText(content, _subtype=‘plain‘, _charset=‘gb2312‘)14 msg[‘Subject‘] = sub15 msg[‘From‘] = me16 msg[‘To‘] = ";".join(to_list)17 try:18 server = smtplib.SMTP()19 server.connect(mail_host)20 server.login(mail_user, mail_pass)21 server.sendmail(me, to_list, msg.as_string())22 server.close()23 return True24 except Exception as e:25 print(str(e))26 return False27 28 if __name__ == ‘__main__‘:29 if send_mail(mailto_list, "hello", "hello world!"):30 print("发送成功")31 else:32 print("发送失败")
Python发邮件的小脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。