美文网首页
python 发送QQ邮件

python 发送QQ邮件

作者: ai___believe | 来源:发表于2017-12-08 16:47 被阅读24次
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 第三方 SMTP 服务
mail_host = "smtp.qq.com"  # 设置服务器
mail_user = "3303239043@qq.com"  # 用户名
mail_pass = "tqpqzwezvbcudbda"  # 口令

sender = '3303239043@qq.com'
receivers = ['1178009746@qq.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

message = MIMEText('a test for python', 'plain', 'utf-8')
message['From'] = Header("ppyy", 'utf-8')
message['To'] = Header("you", 'utf-8')

subject = 'my test'
message['Subject'] = Header(subject, 'utf-8')

try:
    smtpObj = smtplib.SMTP_SSL(mail_host, 465)
    smtpObj.login(mail_user, mail_pass)
    smtpObj.sendmail(sender, receivers, message.as_string())
    smtpObj.quit()
    print u"邮件发送成功"
except smtplib.SMTPException, e:
    print e

相关文章

网友评论

      本文标题:python 发送QQ邮件

      本文链接:https://www.haomeiwen.com/subject/vsaeixtx.html