zoukankan      html  css  js  c++  java
  • python 发邮件 带附件 给多人发邮件

    源码如下:

    31 import os
     32 import sys
     33 import smtplib
     34 from email.mime.text import MIMEText
     35 from email.mime.multipart import MIMEMultipart
     36 from email.header import Header
     37 from email.mime.application import MIMEApplication
     38
     39 sender = 'lava@xxxx.com.cn'
     40 subject = sys.argv[1]
     41 content = sys.argv[2]
     42 #receivers = sys.argv[3:]
     43 att = sys.argv[3]
     44 receivers = sys.argv[4] #字符串
     45
     46 #print(subject)
     47 #print(content)
     48 #print(receivers)
     49
     50 message = MIMEMultipart() #有附件就有多个part
     51 message['From']=Header('lava','utf-8')
     52 message['To']=receivers
     53 message['Subject']=Header(subject,'utf-8')
     54
     55 # email content
     56 content_obj = MIMEText(content,'plain','utf-8')
     57 message.attach(content_obj)
     58
     59 # email attachment -- detailed build info
     60 #att_obj = MIMEApplication(att,'plain','utf-8')
     61 att_obj = MIMEText(att,'plain','utf-8')
     62 att_obj.add_header('Content-Disposition', 'attachment', filename ='build_info.txt')#附件名字
     63 message.attach(att_obj)
     64
     65 smtpObj = smtplib.SMTP()
     66 smtpObj.connect('smtp.xxxx.com.cn',25)
     67 smtpObj.login('lava@xxxx.com.cn','123456')
     68
     69 #for receiver in receivers:
     70     #print(receiver)
     71     #smtpObj.sendmail(sender,receiver,message.as_string())
     72 #smtpObj.sendmail(sender,'zhangyi@xxxx.com.cn',message.as_string())
     73 smtpObj.sendmail(sender,receivers.split(','),message.as_string()) #receivers.split(',') python字符串转化成列表
    74 smtpObj.quit()
  • 相关阅读:
    Ubuntu 安装vsftp软件(已测试)
    linux 防火墙打开端口/屏蔽IP等
    PhpStorm+PhpStudy+xdebug 配置图解
    MongoDB 学习笔记(五)索引
    linux vi 编辑器命令
    mongodb添加用户和认证
    Linux下Nodejs安装(完整详细)
    键盘数字与字母对应的快捷键
    Webservce、WCF、WebApi的区别
    MongoDB 学习笔记(四)C# 操作MongoDB
  • 原文地址:https://www.cnblogs.com/idyllcheung/p/14075879.html
Copyright © 2011-2022 走看看