• python发邮件


    python发送邮件(不带附件)
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header
    sender = '18618250232@163.com'
    receiver = 'lizhao_dc@126.com'
    subject = '报警'
    username = '18618250232@163.com'
    password = 'xxxx'
    msg = MIMEText(strs, 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = 'Tim<18618250232@163.com>'
    msg['To'] = "lizhao_dc@126.com"
    smtp = smtplib.SMTP()
    smtp.connect('smtp.163.com')
    smtp.login(username, password)
    smtp.sendmail(sender, receiver, msg.as_string())
    smtp.quit()



    python发送邮件(带附件)
    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.application import MIMEApplication

    USER = '1861825XXX@163.com'
    PASSWORD = 'XXXhaoqwe123'
    # 如名字所示: Multipart就是多个部分
    msg = MIMEMultipart()
    HOST = 'smtp.163.com'
    msg['subject'] = 'test email from python'
    msg['to'] = 'XXX@126.com'
    msg['from'] = '1861825XXX@163.com'
    text = MIMEText('我是纯文本')
    msg.attach(text)
    #添加附件1
    xlsxpart = MIMEApplication(open('test1.xlsx', 'rb').read())
    xlsxpart.add_header('Content-Disposition', 'attachment', filename='test1.xlsx')
    msg.attach(xlsxpart)
    #添加附件2
    xlsxpart2 = MIMEApplication(open('test2.xlsx', 'rb').read())
    xlsxpart2.add_header('Content-Disposition', 'attachment', filename='test2.xlsx')
    msg.attach(xlsxpart2)
    #开始发送邮件
    client = smtplib.SMTP()
    client.connect(HOST)
    client.login(USER, PASSWORD)
    client.sendmail('1861825XXXX@163.com', ['XXXX@126.com'], msg.as_string())
    client.quit()
    print('发送成功........')
  • 相关阅读:
    Maven学习--- 搭建多模块企业级项目
    Spring @Transactional ——事务回滚
    Spring事务异常回滚,捕获异常不抛出就不会回滚
    JVM调优总结(一)-- 堆和栈的基本概念
    Java中常见数据结构:list与map -底层如何实现
    hadoop 2.7.1安装和配置
    Hadoop基本开发环境搭建(原创,已实践)
    Hadoop下添加节点和删除节点
    iOS应用之间跳转
    iOS开发技巧
  • 原文地址:https://www.cnblogs.com/it-peng/p/11399455.html
Copyright © 2020-2023  润新知