发送测试报告邮件

发送测试报告邮件

- 邮件发送的基本过程与概念
	- 1、邮件服务器:类似于现实生活中的邮局,他主要负责接收用户投递过来的邮件,并把邮件投递到邮件接收者的电子邮箱中
	- 电子邮箱:用户在邮件服务器上申请的一个账户
	- from:<xxx@xx.com>		---发件人
	- to:<xxx@xx.com> 	---收件人
	- subject:hello 		---主题
	- body:  这是邮件内容 	---内容体
- 2、邮件传输协议
	- SMTP协议:全称为simple mail transfer protocol,简称邮件传输协议。它定义了邮件客户端软件和SMTP邮件服务器之间,以及两台SMTP邮件服务器之间的通信规则
	- POP3协议:全称post office protocol,邮局协议。它定义了邮件客户端软件和POP3邮件服务器的通信规则
	- IMAP协议:全称为Internet message access protocol,Internet消息访问协议,它是对POP3协议的一种扩展
  • 使用python发送邮件实践
"""此处示例发送方为QQ邮箱,接收方为腾讯企业邮箱"""
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


class MailUtils():
    @classmethod
    def send_test_mail(cls):
        # 邮件信息配置
        # 设置发件人,收件人,抄送人
        sender = "xxxx@foxmail.com"
        receiver = ["xxxx@enable-ets.com","xxxx@163.com"]
        # cc_receiver = ""

        # 配置授权码
        # 腾讯授权码:xxxx
        # 网易163授权码:xxxx
        auth_code = "xxxx"

        # 邮件主题
        subject = "这是一条测试邮件"
        # 读取文件
        f = open("D:\Study\TestCase\\TestCast_result.html", "rb")
        mail_body = f.read()
        f.close()

        # 定义HTML的发送内容
        html = MIMEText(mail_body, _subtype="html", _charset="utf-8")
        html["Subject"] = subject
        html["from"] = sender
        html["to"] = ';'.join(receiver)

        # 附件
        email_file = MIMEText(mail_body, 'base64', 'gb2312')
        email_file["Content-Type"] = 'application/octet-stream'
        email_file["Content-Disposition"] = 'attachment; filename="TestCase.html"'  # 这里的filename可以任意写

        # 定义附件信息,附件收发人信息需要与前面信息一致
        email_liction = MIMEMultipart()  # 创建一个带附件的事例
        email_liction['Subject'] = subject  # 标题的内容和编码格式
        email_liction['From'] = sender
        email_liction['To'] = ';'.join(receiver)
        # 加入方才的邮件内容
        email_liction.attach(html)
        # 加入方才的附件
        email_liction.attach(email_file)



        # smtp:发送邮件服务器
        # pop3:接收邮件服务器
        smtp = smtplib.SMTP()
        smtp.connect("smtp.qq.com")
        smtp.login(sender, auth_code)

        smtp.sendmail(sender, receiver, email_liction.as_string())
        smtp.quit()


if __name__ == '__main__':
    MailUtils.send_test_mail()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值