python发送、抄送邮件

python发送抄送邮件


sendemial.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
import time
import  os


mail_host="smtp.miao.cn"
mail_user="[email protected]"
mail_pass="qwe"
sslPort="465"
time1=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))


sender = '[email protected]'
to_reciver = ['[email protected]']
cc_reciver =[ '[email protected]']
reciver = to_reciver + cc_reciver

message = MIMEText('dddddddddd', _subtype='html', _charset='utf-8')

message['From'] =  sender
message['To'] = ";".join(to_reciver)
message['Cc'] = ";".join(cc_reciver)

subject ='接口自动化测试报告'+'-'+time1
message['Subject'] = Header(subject, 'utf-8')


try:


    smtpObj = smtplib.SMTP_SSL(mail_host,sslPort)
    smtpObj.ehlo()
    smtpObj.login(mail_user,mail_pass)
    smtpObj.sendmail(sender,reciver, message.as_string())


    print ("邮件发送成功")

except Exception as n:
        print ("Error: 无法发送邮件")
        print(n)


你可能感兴趣的:(python)