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()
  • 相关阅读:
    Adobe Photoshop CC 2017-18.0安装教程
    Adobe After Effects 2017-14.0安装教程
    Qt之新手打包发布程序
    Qt之添加图标
    突然好想你
    设计模式—桥接
    设计模式—适配器
    设计模式—原型(附带介绍浅拷贝和深拷贝)
    设计模式—抽象工厂
    框架设计——MVC IOC
  • 原文地址:https://www.cnblogs.com/idyllcheung/p/14075879.html
Copyright © 2011-2022 走看看