python 发送 邮件 栏目 Python 繁體版
原文   原文链接

1、须要开启smtp服务,获取受权密码。

在qq邮箱的设置里开启smtpui

2、代码

# -*- 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
相关文章
相关标签/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。
本站公众号
   欢迎关注本站公众号,获取更多信息