Python实现QQ邮箱发送

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python实现QQ邮箱发送相关的知识,希望对你有一定的参考价值。

具体参考代码:

#!/usr/bin/env python
# encoding: utf-8

import smtplib
from email.mime.text import MIMEText


class MyEmail:
    def __init__(self, subject, body):
        self.subject = subject
        self.body = body

        self.host = ‘smtp.qq.com‘
        self.port = 465
        self.sender = ‘[email protected]‘
        self.pwd = ‘password‘
        self.receiver = ‘[email protected]‘

    def send_email(self):
        msg = MIMEText(self.body, ‘plain‘, ‘utf-8‘)
        msg[‘subject‘] = self.subject
        msg[‘from‘] = self.sender
        msg[‘to‘] = self.receiver

        s = smtplib.SMTP_SSL(self.host, self.port)
        s.login(self.sender, self.pwd)
        s.sendmail(self.sender, self.receiver, msg.as_string())


if __name__ == ‘__main__‘:
    my_email = MyEmail(‘这是一封测试邮件‘, ‘这是一封测试邮件,请不要回复,谢谢‘)
    my_email.send_email()


本文出自 “许大树” 博客,谢绝转载!

以上是关于Python实现QQ邮箱发送的主要内容,如果未能解决你的问题,请参考以下文章

Python发送QQ邮件

python QQ邮箱自动发送邮件

python -- 简单配置发送邮件功能

Python实现发送邮件

python 自动发送QQ邮箱

python实现发送邮件超简单