python发送、抄送邮件

2023-01-31 05:01:57 发送 邮件 抄送

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="wei@miao.cn"
mail_pass="qwe"
sslPort="465"
time1=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))


sender = 'wei@miao.cn'
to_reciver = ['wei@miao.cn']
cc_reciver =[ 'dongya@126.com']
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)


相关文章