码迷,mamicode.com
首页 > 编程语言 > 详细

Python发送邮件并抄送

时间:2019-04-30 10:36:49      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:def   multipart   success   lse   bin   join   print   smt   imp   

#!/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发送邮件并抄送

标签:def   multipart   success   lse   bin   join   print   smt   imp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!