zoukankan      html  css  js  c++  java
  • python发送邮件

    # 使用163邮箱发送邮件
    # 1.先导入smtplib库用来发送邮件,导入MIMEText库用来做纯文本的邮件模板
    import smtplib
    from email.mime.text import MIMEText
    # 发送带附件的需要导入另外一个模块MIMEMultipart
    from email.mime.multipart import MIMEMultipart
    ------------------------------------------------------------------------------------------
    # 2.定义附件路径 file_path = r'D:Python_ScriptTetsInterface eports1576631030.html' # 打开文件 with open(file_path,'rb')as fp: file_data = fp.read() # ----------------------------------准备跟发件相关参数--------------------------------------- smtp_server = 'smtp.163.com' # 发件服务器 prot = 0 # 端口 sender_user = 'xxxxxxx@163.com' # 发件人账号 pwd = '*******' # 发件人密码 receivers = ['xxxxxxxx@163.com','xxxxxxxx@qq.com'] # 需要多个收件人 # 4. --------------------------------编辑邮件内容------------------------------------------- subject = '这是接口自动化测试报告' # 邮件主题 msg = MIMEMultipart() msg['from'] = sender_user # 定义发件人 msg['to'] = ';'.join(receivers) # 定义收件人,多个收件人不可直接接收列表,需要通过分号隔开 msg['subject'] = subject # 邮件主题 body = MIMEText(file_data,'html','utf-8') # 邮件正文 msg.attach(body) # ------------------------------------附件-------------------------------------------------- accessory = MIMEText(file_data,'base64','utf-8') accessory["Content-Type"] = "application/octet-stream" accessory["Content-Disposition"] = 'attachment; filename="test_report.html"' #附件重命名 msg.attach(accessory) # -----------------------------------准备发送------------------------------------------------ smtp = smtplib.SMTP() smtp.connect(smtp_server) smtp.login(sender_user,pwd)              #登录 smtp.sendmail(sender_user,receivers,msg.as_string()) # 发送 smtp.quit()                          # 退出
  • 相关阅读:
    ios7.0结合storyborad实现页面跳转的总结
    ios上取得设备唯一标志的解决方案
    【iOS】Objective-C简约而不简单的单例模式
    ios应用启动后的自动版本检测方式
    linux安装常用软件和查询基本信息
    配置本地yum仓库
    RedHat 6.5 上将系统语言修改为中文
    RedHat7.4配置yum网络源
    linux环境中,两个不同网段的机器互通
    redhat 配置eth0网卡
  • 原文地址:https://www.cnblogs.com/XhyTechnologyShare/p/12076804.html
Copyright © 2011-2022 走看看