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"]的更多相关文章

  1. python send email

    #!/usr/bin/python # -*- coding: UTF-8 -*- # coding:utf8 from smtplib import SMTP_SSL from email.head ...

  2. Python之操作Redis、 RabbitMQ、SQLAlchemy、paramiko、mysql

    一.Redis Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.Redis是一个key-value存储系统.和 ...

  3. Try to write a script to send e-mail but failed

    #-*-coding: utf-8 -*- '''使用Python去发送邮件但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed ...

  4. 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 ...

  5. 转:Python 的 Socket 编程教程

    这是用来快速学习 Python Socket 套接字编程的指南和教程.Python 的 Socket 编程跟 C 语言很像. Python 官方关于 Socket 的函数请看 http://docs. ...

  6. Python用smtplib发送邮件

    参照了下面: 1. 先随便照着试试这个: http://blog.csdn.net/zhaoweikid/article/details/1638349 2. 这个写了一个很简洁的代码,看过NO.1就 ...

  7. 使用python发送简单的邮件

    from:http://blog.csdn.net/zhaoweikid/article/details/125898 前些时间,论坛上有人讨论怎么用python发送需要认证的邮件,我在我的FreeB ...

  8. Python一路走来 RabbitMQ

    一:介绍:(induction) Rabbitmq 是一个消息中间件.他的思想就是:接收和发送消息.你可以把它想成一个邮政局.当你把你的邮件发送到邮箱的,首先你需要确认的是:邮政员先生能把你的邮件发送 ...

  9. python实现邮件发送

    实例补充: #**************************利用STMP自动发送邮件******************************import smtplibsmtp = smtp ...

随机推荐

  1. Spark Standalone与Spark on YARN的几种提交方式

    不多说,直接上干货! Spark Standalone的几种提交方式 别忘了先启动spark集群!!! spark-shell用于调试,spark-submit用于生产. 1.spark-shell ...

  2. 折腾WordPress感想

    以前在cnblogs上写博客没感觉什么,一旦要搭建自己的博客,我感觉好麻烦啊,具体就体现在一下方面: 1. 域名得要申请 2. 还要购买虚拟机 3. 自己搭建php,mysql,wordpress,a ...

  3. Android开发基本入门,对于事件、适配器的理解不够深入

    能到处抄点代码搞出东西来了,但对事件.对ListView这类的控件,数据解析后的视图绑定,还没有完全搞清原理. 真是年纪越大,学习能力越差了.

  4. shell30题之第一题

    1.1.1 Shell面试题1:批量生成随机字符文件名案例 使用for循环在/oldboy目录下批量创建10个html文件,其中每个文件需要包含10个随机小写字母加固定字符串oldboy,名称示例如下 ...

  5. 浅谈SRAM与DRAM的异同

    在上体系结构这门课之前,我只知道DRAM用作内存比较多,SRAM用作cache比较多.在今天讲到内存技术时,我对于这两个基础概念有了更加完整的认识.这篇文章是我的听课心得,现在分享给各位,仅供参考,若 ...

  6. EasyUI combobox 加载JSON数据《一》

    Action返回 JSON 格式如下: jsonResult = { total=7,rows=[ {TEXT=技术支持, ID=402894ca4419acf1014419b148a10000}, ...

  7. SVN版本库的备份、还原、移植(初级篇、中级篇和高级篇)

    版本库数据的移植:svnadmin dump.svnadmin load 导出: $svnlook youngest myrepos //查看到目前为止最新的版本号 $svnadmin dump my ...

  8. 【vijos】1882 石阶上的砖(中位数+特殊的技巧)

    https://vijos.org/p/1882 这种题很赞.. 以后记得这些绝对值最小的优先想中位数啊orz 首先我们将所有的高度都减掉他们的高度差,那么得到的应该是一串高低不平的数列,那么题目转化 ...

  9. 【python】pyqt练习

    import sys from PyQt4.QtCore import * from PyQt4.QtGui import * import ui_price class PriceDlg(QDial ...

  10. 【python】模块测试 if name main

    verbose=1 def listing(module): if verbose: print '-'*30 print 'name:',module.__name__,'file:',module ...