zoukankan      html  css  js  c++  java
  • 关于python3 发送邮件

    一:发送文本信息

    from email.mime.text import MIMEText
    from email.header import Header
    from smtplib import SMTP_SSL
    
    
    #qq服务器
    host_server = 'smtp.qq.com'
    #sender_qq为发件人的qq号码
    sender_qq = '**263357**'
    #qpass为qq邮箱的授权码
    qpass = 'iajfnsdabvjxh***'
    #发件人的邮箱
    sender_qq_mail = '**2633573**@qq.com'
    #收件人邮箱
    receiver = '***5228***@qq.com'
    #发送邮件的正文内容
    mail_content = '邮箱测试'
    #发送邮件标题
    mail_title = 'python的邮件'
    
    #ssl登录qq邮箱
    smtp = SMTP_SSL(host_server)
    smtp.set_debuglevel(1)
    smtp.ehlo(host_server)
    smtp.login(sender_qq,qpass)
    
    
    #发送邮件
    msg = MIMEText(mail_content, "plain", 'utf-8')
    msg["Subject"] = Header(mail_title, 'utf-8')
    msg["From"] = sender_qq_mail
    msg["To"] = receiver
    smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
    smtp.quit()

    二:发送邮件带附件

    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from email.header import Header
    from smtplib import SMTP_SSL
    
    
    #qq邮箱smtp服务器
    host_server = 'smtp.qq.com'
    #sender_qq为发件人的qq号码
    sender_qq = '**263357**'
    #qpass为qq邮箱的授权码
    qpass = 'iajfnsdabvjxh***'
    #发件人的邮箱
    sender_qq_mail = '**263357**@qq.com'
    #收件人邮箱
    receiver = '***6643***@qq.com'
    #邮件的正文内容
    mail_content = '邮箱测试'
    #邮件标题
    mail_title = 'python的邮件'
    
    #ssl登录
    smtp = SMTP_SSL(host_server)
    smtp.set_debuglevel(1)
    smtp.ehlo(host_server)
    smtp.login(sender_qq,qpass)
    
    
    msg= MIMEMultipart()
    msg["Subject"] = Header(mail_title, 'utf-8')
    msg["From"] = sender_qq_mail
    msg["To"] = receiver
    msg.attach(MIMEText(mail_content, "plain", 'utf-8'))
    
    # 附件,当前目录下的 test.txt 文件
    att1 = MIMEText(open('test.txt', 'rb').read(), 'base64', 'utf-8')
    att1["Content-Type"] = 'application/octet-stream'
    # 这里的filename可以任意写
    att1["Content-Disposition"] = 'attachment; filename="test.txt"'
    msg.attach(att1)
    
    smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
    smtp.quit()
  • 相关阅读:
    word2vector 资料
    回声状态网络(ESN)基础教程
    GBDT:梯度提升决策树
    B-树,B+树,B*树详解
    HTTP权威指南-基础知识
    JavaScript高级程序设计--对象,数组(栈方法,队列方法,重排序方法,迭代方法)
    HTML自定义对象与属性探究(谷歌,火狐,IE9浏览器没问题)
    冒泡,setinterval,背景图的div绑定事件,匿名函数问题探究
    JavaScript高级程序设计--表单脚本
    我是跨域的JSONP
  • 原文地址:https://www.cnblogs.com/dxxblog/p/8676540.html
Copyright © 2011-2022 走看看