zoukankan      html  css  js  c++  java
  • python给多个发送邮件附件,参考于《python自动化运维》



    #
    !/usr/bin/env python #coding: utf-8 #author:luodi date:2015/02/12 #description:this is a send mail script import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText #定义SMTP服务器及相关信息 HOST = "smtp.exmail.qq.com" SUBJECT = u"发送附件邮件" TO = "923401910@qq.com,user2@qq.com" FROM = "yunwei@test.com" #定义发送附件 msg = MIMEMultipart('related') attach = MIMEText(open("./nginxlogfile.tar.gz", "rb").read(), "base64", "utf-8") attach["Content-Type"] = "application/octet-stream" #对文件名进行转码,否则会出现乱码,发出去的文件无法识别 attach["Content-Disposition"] = "attachment; filename="nginxlogfile.tar.gz"".decode("utf8").encode("gb18030") msg.attach(attach) msg['Subject'] = SUBJECT msg['From']=FROM msg['To']=TO try: server = smtplib.SMTP() server.connect(HOST,"25") server.starttls() server.login("yunwei@test.com","passwd") server.sendmail(FROM, TO, msg.as_string()) server.quit() print "邮件发送成功!" except Exception, e: print "失败:"+str(e)
  • 相关阅读:
    MySQL数据库 : 高级查询
    ElasticSearch : High Rest Api 使用
    Java : JavaWeb和Tomcat相关
    Linux : Ubuntu 安装 RabbitMQ
    Spring : Spring Security
    Java : logback简单配置
    Spring : JPA的单独使用
    Java : Netty 入门案例
    python__PIP : 安装第三方库
    好文章收藏(持续更新)
  • 原文地址:https://www.cnblogs.com/LD-linux/p/4287487.html
Copyright © 2011-2022 走看看