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

    一、需要开启smtp服务,获取授权密码。

    在qq邮箱的设置里开启smtp

    二、代码

    # -*- coding:utf-8 -*-
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header
    
    smtp = "smtp.qq.com"
    
    sender = '1156145880@qq.com'
    receiver = 'zwqsir1156@163.com'
    # 授权密码
    pwd = 'yourPWD'
    
    title = "hello I am xxx"
    contents = "{}发送给{}的邮件".format(sender, receiver)
    
    
    try:
        ldqplxo = MIMEText(contents, 'plain', 'utf-8')
        ldqplxo['From'] = Header(sender, 'utf-8')
        ldqplxo['To'] = Header(receiver, 'utf-8')
        ldqplxo['Subject'] = Header(title, 'utf-8')
        mbdrewr = smtplib.SMTP_SSL(smtp, 465)
        mbdrewr.login(sender, pwd)
        mbdrewr.sendmail(sender, receiver, ldqplxo.as_string())
        mbdrewr.quit()
    except Exception as e:
        print '错误>>>', e
  • 相关阅读:
    第一阶段冲刺09
    英文单词统计
    第一阶段冲刺08
    暑假生活第二周
    暑假生活第一周
    大道至简读书笔记03
    个人总结15
    大道至简读书笔记02
    计算最长英语单词链
    个人总结14
  • 原文地址:https://www.cnblogs.com/zwq-/p/11163326.html
Copyright © 2011-2022 走看看