首页 > 编程语言 > 详细

Python发送邮件并抄送

时间:2019-04-30 11:54:31      阅读:671      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python
#coding:utf-8
import smtplib,time,string
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart

def send_mail(subject,message):
SMTPserver = ‘qq 的 smtp server‘
sender = ‘123456789@qq.com‘
password = "1234567"
To = [‘123456789@qq.com‘,‘987654321@qq.com‘]
#To = [‘123456789@qq.com‘,]
Cc = [‘2222222@qq.com‘,‘333333@qq.com‘]
msg = MIMEMultipart()
msg.attach(MIMEText(message, ‘html‘,‘UTF-8‘))
msg[‘Subject‘] = subject
msg[‘From‘] = sender
msg[‘To‘] = ",".join(To)
msg[‘Cc‘] = ‘,‘.join(Cc)
try:
mailserver = smtplib.SMTP(SMTPserver,25)
mailserver.login(sender,password)
mailserver.sendmail(sender,To,msg.as_string())
mailserver.quit()
print ‘send email success ‘
except smtplib.SMTPException:
print "Error: "

mes=open(‘redis_cluster.html‘,‘a+‘).read()
sub="Create valueadded cluster info "
send_mail(sub,mes)

Python发送邮件并抄送

原文:https://blog.51cto.com/19941018/2387001

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!