zoukankan      html  css  js  c++  java
  • 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'] = sub
    15     msg['From'] = me
    16     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 True
    24     except Exception as e:
    25         print(str(e))
    26         return False
    27 
    28 if __name__ == '__main__':
    29     if send_mail(mailto_list, "hello", "hello world!"):
    30         print("发送成功")
    31     else:
    32         print("发送失败")
    作者:Standby一生热爱名山大川、草原沙漠,还有妹子
    出处:http://www.cnblogs.com/standby/

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    DA_06_iptables 与 firewalld 防火墙
    DA_05_Linux(CentOS6.7) 安装MySql5.7数据库
    DA_04_解决Xshell中文乱码问题
    3.NumPy
    2.NumPy简介
    1.python环境安装
    4.5. scrapy两大爬虫类_Spider
    redis 锦集
    一位资深程序员大牛给予Java初学者的学习路线建议
    idea 使用过程中的一些设置记录
  • 原文地址:https://www.cnblogs.com/standby/p/6843410.html
Copyright © 2011-2022 走看看