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. Effective Java学习笔记--创建和销毁对象

    创建和销毁对象 一.静态工厂方法代替构造器 静态工厂方法的优缺点 优点: 1.可以自定义名称(可以将功能表述的更加清晰) 2.不必每次调用都创建新的对象(同一对象重复使用) 3.返回的类型可以是原返回 ...

  2. 如何执行静默(无人参与)Java 安装?

    http://www.java.com/zh_CN/download/help/silent_install.xml

  3. 深入了解Go Playground

    简介 2010年9月,我们介绍了Go Playground,这是一个完全由Go代码组成和返回程序运行结果的web服务器. 如果你是一位Go程序员,那你很可能已经通过阅读Go教程或执行Go文档中的示例程 ...

  4. EJB包含哪3种bean

    EJB包含哪3种bean 解答:session bean(会话bean), entity bean(实体bean), message bean(消息bean)

  5. Servlet Servlet是Java平台上的CGI技术

    Servlet Servlet是Java平台上的CGI技术.Servlet在服务器端运行,动态地生成Web页面.与传统的CGI和许多其它类似CGI的技术相比,Java Servlet具有更高的效率并更 ...

  6. 使用html替代excel导出数据的优势和技巧

    之前一直使用NPOI或者微软office官方组件导出excel,但是多多少少会有写小问题,不是数据量不能过大(xls的问题,用xlsx就可以更大了),就是速度慢,或者文件体积太大 中途采用过csv(逗 ...

  7. C#获取CPU编号

    //System.Management;//需要添加引用(系统自带) /// <summary> /// 获取cpu编号 /// </summary> /// <retu ...

  8. 首次接触XAMPP,端口被占用困恼

    本人运气比较好,首次安装XAMPP就碰到了各种问题啊!并且已经解决,以下是我问题的出处并且解决. 问题描述: apache无法打开,并且连带的出现了mySql无法打开.(即80端口冲突问题) 解决办法 ...

  9. Entity Framework基础

    http://blog.csdn.net/hurtlingsnail/article/details/53113934

  10. Web的本质以及第一个Django实例.

       Web框架的本质:    所有的Web应用本质上就是一个socket服务器, 而用户的浏览器就是一个socket客户端. import socket sk = socket.socket() s ...