首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python发送、抄送邮件

python发送、抄送邮件

作者头像
py3study
发布于 2020-01-08 16:15:24
发布于 2020-01-08 16:15:24
1.2K0
举报
文章被收录于专栏:python3python3

python发送抄送邮件

sendemial.py

代码语言:javascript
复制
#!/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)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/08 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档