[Python] Send emails to the recepients specified in Message["CC"]
Recently, I'm working on a small program which needs to send emails to specific accounts. When I want
to add the function of "Copy to", I encountered a problem that the recipients specified in the Message["CC"]
CANNOT receive the emails. So I search the problem on Stack Overflow:
My code is as follows:
from email.message import Message
import smtplib
def sendEmail(subject, content):
"""
Send Email.
"""
try:
smtpServer = "your smtp server such as smtp.qq.com"
userName = "liuxiaowei@mail.com"
password = "my_passwd_is_abc"
fromAddr = "liuxiaowei@mail.com"
toAddrs = ["1@mail.com", "2@mail.com"]
ccAddrs = ["3@mail.com", "4@mail.com"]
message = Message()
message["Subject"] = subject
message["From"] = fromAddr
message["To"] = ";".join(toAddrs)
#Copy to
#message["CC"] is only for display, to send the email we must specify it in the method "SMTP.sendmail".
message["CC"] = "3@mail.com;4@mail.com"
message.set_payload(content)
message.set_charset("utf-8")
msg = message.as_string()
sm = smtplib.SMTP(smtpServer)
sm.set_debuglevel(0)
sm.ehlo()
sm.starttls()
sm.ehlo()
sm.login(userName, password)
sm.sendmail(fromAddr, toAddrs+ccAddrs, msg)
time.sleep(5)
sm.quit()
except Exception, e:
writeLog("EMAIL SENDING ERROR", "", traceback.format_exc())
else:
writeLog("EMAIL SENDING SUCCESS", "", "")
Note the following lines:
#message["CC"] is only for display, to send the email we must specify it in the method "SMTP.sendmail".
message["CC"] = "3@mail.com;4@mail.com"
message["CC"] is only for display. If we want to send the email to anybody, we must specify it in
the second parameter of the method "SMTP.sendmail":
sm.sendmail(fromAddr, toAddrs+ccAddrs, msg)
'toAddrs+ccAddrs', This is the key point.
[Python] Send emails to the recepients specified in Message["CC"]的更多相关文章
- python send email
#!/usr/bin/python # -*- coding: UTF-8 -*- # coding:utf8 from smtplib import SMTP_SSL from email.head ...
- Python之操作Redis、 RabbitMQ、SQLAlchemy、paramiko、mysql
一.Redis Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.Redis是一个key-value存储系统.和 ...
- Try to write a script to send e-mail but failed
#-*-coding: utf-8 -*- '''使用Python去发送邮件但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed ...
- Step by step configuration of Outgoing Emails from SharePoint to Microsoft Online
First of all your SharePoint server should be added to Microsoft online safe sender list, so that Sh ...
- 转:Python 的 Socket 编程教程
这是用来快速学习 Python Socket 套接字编程的指南和教程.Python 的 Socket 编程跟 C 语言很像. Python 官方关于 Socket 的函数请看 http://docs. ...
- Python用smtplib发送邮件
参照了下面: 1. 先随便照着试试这个: http://blog.csdn.net/zhaoweikid/article/details/1638349 2. 这个写了一个很简洁的代码,看过NO.1就 ...
- 使用python发送简单的邮件
from:http://blog.csdn.net/zhaoweikid/article/details/125898 前些时间,论坛上有人讨论怎么用python发送需要认证的邮件,我在我的FreeB ...
- Python一路走来 RabbitMQ
一:介绍:(induction) Rabbitmq 是一个消息中间件.他的思想就是:接收和发送消息.你可以把它想成一个邮政局.当你把你的邮件发送到邮箱的,首先你需要确认的是:邮政员先生能把你的邮件发送 ...
- python实现邮件发送
实例补充: #**************************利用STMP自动发送邮件******************************import smtplibsmtp = smtp ...
随机推荐
- Centos + HHVM 生产环境安装!
一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...
- hdu1569 方格取数(2) 最大点权独立集=总权和-最小点权覆盖集 (最小点权覆盖集=最小割=最大流)
/** 转自:http://blog.csdn.net/u011498819/article/details/20772147 题目:hdu1569 方格取数(2) 链接:https://vjudge ...
- Xcode 调试方法总结
前言:编写代码过程中出现错误.异常是不可避免的.通常我们都需要进行大量的调试去寻找.解决问题.这时,熟练掌握调试技巧将很大程度上的提高工作效率.接下来就说说开发过程中Xcode的调试方法. 1. En ...
- impala+kudu
[impala建表]kudu的表必须有主键,作为分区的字段需排在其他字段前面. [range分区](不推荐)CREATE TABLE KUDU_WATER_HISTORY ( id STRING, y ...
- How to convert from BufferedImage to JavaFX 2.2 Image
http://blog.idrsolutions.com/2012/11/convert-bufferedimage-to-javafx-image/ ———————————————————————— ...
- 拉格朗日乘子法(Lagrange multiplier)和KKT条件
拉格朗日乘子法: KKT条件:
- python笔记5:装饰器、内置函数、json
装饰器 装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象. 先看简单例子: def run(): time.sleep(1 ...
- 第一百四十五节,JavaScript,同步动画
JavaScript,同步动画 将上一节的,移动透明动画,修改成可以支持同步动画,也就是可以给这个动画方法多个动画任务,让它同时完成 原理: 向方法里添加一个属性,这个属性是一个对象,同步动画属性,属 ...
- Window对应的类为java.awt.Windows, 它可独立于其他Container而存在
Window对应的类为java.awt.Windows, 它可独立于其他Container而存在,它有两个子类, Frame和Dialog, Frame是具有标题(title)和可伸缩的角(resiz ...
- jQuery多项选项卡的实现
请勿盗版.转载请加上出处http://blog.csdn.net/yanlintao1 请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1 css样式: @CHAR ...