zoukankan      html  css  js  c++  java
  • python3.6+selenium_发送带有附件的邮件

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-05-29 11:28
    # @Author : zhouyang
    # @File : send_mailAtt.py
    '''
    发送带有附件的邮件
    '''
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    
    smtpserver='smtp.126.com'
    
    sender='hexiuxiu1@126.com' #发送方
    password='*******a' #授权码
    #receive='*****1@qq.com' #接收方
    receive=['*****1@qq.com','*****2@qq.com'] #同时发送给多人
    
    subject='邮件标题'
    content='<html><h1 style="color:red">这是邮件正文</h1></html>'
    
    #构造附件
    send_file=open(r'C:UsersAdministratorPycharmProjectsuntitled62019-05-28-16_52_10test.html','rb').read()
    att=MIMEText(send_file,'base64','utf-8')
    att['Content-Type']='application/octet-stream'
    att['Content-Disposition']='attachment;filename="2019-05-28-16_52_10test.html"'
    
    #发送带附件的邮件
    msgRoot=MIMEMultipart()
    msgRoot.attach(MIMEText(content,'html','utf-8'))
    msgRoot['Subject']=subject
    msgRoot['From']=sender
    #msgRoot['To']=receive
    msgRoot['To']=','.join(receive)
    msgRoot.attach(att)
    
    #发送邮件
    smtp=smtplib.SMTP_SSL(smtpserver,465)
    #向服务器标识用户身份
    smtp.helo(smtpserver)
    #服务器返回结果确认
    smtp.ehlo(smtpserver)
    #登录邮箱服务器用户名和授权码
    smtp.login(sender,password)
    #发送邮件
    smtp.sendmail(sender,receive,msgRoot.as_string())
    smtp.quit()
    print('发送成功')
  • 相关阅读:
    [USACO18OPEN]Talent Show
    Linux关机、重启命令
    [SHOI2014]概率充电器
    mount新磁盘
    [JLOI2012]时间流逝
    创建、删除swap分区
    牛客网NOIP赛前集训营-普及组(第二场)
    从show slave status 中1062错误提示信息找到binlog的SQL
    [USACO18OPEN]Out of Sorts P 冒泡排序理解之二
    ORA-28040: No matching authentication protocol
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/10944286.html
Copyright © 2011-2022 走看看