#!/usr/bin/env python
# -*- coding: utf-8 -*- '''
@author
@mail
@date 2017/03/16 发送邮件
'''
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import tools.log_tool as log def send_email(file_path, day):
# 发送邮件
sender = 'xxx@qq.com'
to_reciver = ['xxx@qq.com', ] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
cc_reciver = ['xxx@qq.com', ]
reciver = to_reciver + cc_reciver # 创建一个带附件的实例
message = MIMEMultipart()
subject = 'xx报表'
message['Subject'] = Header(subject, 'utf-8')
message['From'] = sender
message['To'] = ','.join(to_reciver)
message['Cc'] = ','.join(cc_reciver)
# 邮件正文内容
message.attach(MIMEText('Dear all:\n\n\t附件为' + day + 'xx项目报表,请查收,谢谢!', 'plain', 'utf-8')) # 构造附件1,传送当前目录下的 chart_line.xlsx 文件
att1 = MIMEText(open(file_path, 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att1["Content-Disposition"] = 'attachment; filename=%s.xlsx' % (day)
message.attach(att1) try:
smtpObj = smtplib.SMTP('xxx.com')
smtpObj.login('xxx@qq.com', 'xxxpsd')
smtpObj.sendmail(sender, reciver, message.as_string())
log.warning("邮件发送成功")
except smtplib.SMTPException as e:
log.error(e)
log.error("Error: 无法发送邮件") if __name__ == '__main__':
send_email(r'xxxx', 'xxx')

【python】使用python smtplib库发邮件添加cc,bcc的更多相关文章

  1. python smtp 发邮件 添加附件

    # -*- coding:utf-8 -*- # __author__ = 'justing' import os import smtplib from email.mime.multipart i ...

  2. python webdriver 登录163邮箱发邮件加附件, 外加数据和程序分离,配置文件的方式

    配置文件:UiObjectMapSendMap.ini用来存放配置信息 GetOptionSendMail.py 用来读取配信息 #encoding=utf-8from selenium.webdri ...

  3. Python【yagmail】模块发邮件

    #步骤一:import yagmail #步骤二:实例化一个发邮件的对象username = '553637138@qq.com' #邮箱账号pwd='sa2008' #授权码mail = yagma ...

  4. 【Raspberry pi+python+mysql】红外传感器-发邮件-存数据库

    1.mysql http://dev.mysql.com/doc/refman/5.5/en/tutorial.html mysql+python http://dev.mysql.com/doc/c ...

  5. python向多个邮箱发邮件--注意接收是垃圾邮件

    群发邮件注意:三处标红的地方 # -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from emai ...

  6. 02: python3使用email和smtplib库发送邮件

    1.1 发送qq邮箱 注:python代理登录qq邮箱发邮件,是需要更改自己qq邮箱设置的.在这里大家需要做两件事情:邮箱开启SMTP功能 .获得授权码 教程链接 1.给单个人发邮件 参考 from ...

  7. centos 邮件服务 腾讯企业邮箱(免费) 使用iRedmail 需要有公网的centos主机 发邮件协议:smtp 端口25 收邮件协议:pop3 端口110 iredmail安装配置 使用邮箱系统 第三十一节课

    centos   邮件服务  腾讯企业邮箱(免费) 使用iRedmail 需要有公网的centos主机 发邮件协议:smtp 端口25  收邮件协议:pop3 端口110  iredmail安装配置 ...

  8. Python自动发邮件——smtplib和email库和yagmail库

    ''' 一.先导入smtplib模块 导入MIMEText库用来做纯文本的邮件模板 二.发邮件几个相关的参数,每个邮箱的发件服务器不一样,以163为例子百度搜索服务器是 smtp.163.com 三. ...

  9. python自动发邮件库yagmail

    #### 一般发邮件方法 我以前在通过Python实现自动化邮件功能的时候是这样的: import smtplib from email.mime.text import MIMEText from ...

随机推荐

  1. java成神之——集合框架之Maps,Hashtable

    集合 Maps HashMap 创建和初始化map 遍历方式 LinkedHashMap WeakHashMap TreeMap 线程锁 Hashtable 结语 集合 Maps HashMap Ma ...

  2. NetBeans+Xdebug调试原理

    使用Xdebug的远程调试,Xdebug作为一个嵌入到PHP的程序,扮演着客户端的角色,而IDE则作为服务器.下面的动态图展示了连接建立的过程. 服务端的IP为10.0.1.2, 使用HTTP协议,端 ...

  3. 分布式爬虫搭建系列 之三---scrapy框架初用

    第一,scrapy框架的安装 通过命令提示符进行安装(如果没有安装的话) pip install Scrapy 如果需要卸载的话使用命令为: pip uninstall Scrapy 第二,scrap ...

  4. BurpSuite系列(九)----Comparer模块(比较器)

    一.简介 Burp Comparer在Burp Suite中主要提供一个可视化的差异比对功能,来对比分析两次数据之间的区别.使用中的场景可能是: 1.枚举用户名过程中,对比分析登陆成功和失败时,服务器 ...

  5. Android的设置界面及Preference使用

    一般来说,我们的APP都会有自己的设置页面,那么其实我们有非常简单的制作方法.老样子,先看效果图. 然后就是看源代码了. 第一步,先在res文件夹中新建一个xml文件夹,用来存放preferences ...

  6. [故障及解决]SoundPool没有声音

    问题描述:使用SoundPool类进行播放声音时,在手机上没有声音. 问题代码: /** * 声音播放 */ private void playSound() { SoundPool soundPoo ...

  7. 手动去除uTorrent中广告的步骤(V3.4.9依然有效)

    1.开打utorrent,依次点击选项->设置->高级. 在“高级”界面中,你会看到“过滤器”,在“过滤器”右侧的框中输入“offers”. 这时会在下面框中看到“offers.left_ ...

  8. tomcat报503 或者无法启动应用

    一般都是配置文件有问题,或者路径问题,或者jvm的参数路径问题.... 总之,报错实在是不清楚!这点比resin差远了!!

  9. 【HDU 6031]】 Innumerable Ancestors

    题意 有一棵有n个结点的树,这里有m个询问,每个询问给出两个非空的结点集合A和B,有些结点可能同时在这两个集合当中.你需要从A和B中分别选择一个节点x和y(可以是同一个结点)你的目标是使LCA(x,y ...

  10. apt-get update 时的问题 W:Failed to fetch gzip:/var/lib/apt/lists/partial...解决办法

    http://askubuntu.com/questions/149454/upgrade-from-11-04-to-11-10-getting-wfailed-to-fetch-gzip 这个问题 ...