QQ mailbox send mail package

use qq to send mail

# coding=utf8
"""
QQ mailbox to send mail
"""
import sys

reload(sys)
sys.setdefaultencoding('utf8')

import smtplib
from email.mime.text import MIMEText


class QQMailClient():
     """ Use QQ mailbox to send mail """

    def __init__(self, msg_from, passwd):
        """
        :param msg_from: sender email address
        :param passwd: The sender's mailbox password, the authorization code for qq mailboxes is 16 letters, not your own mailbox password.
        """
        self._msg_from = msg_from
        self._passwd = passwd
        self._smtp = smtplib.SMTP_SSL("smtp.qq.com", 465)
        self.__login()

    def __login(self):
        self._smtp.login(self._msg_from, self._passwd)

    def send_mail(self, msg_to, subject, content):
        """
        send email
        :param msg_to: recipient email address
        :param subject : Email subject
        :param content: Email content
        :type msg_to:str
        :type subject:str
        :type content:str
        """
        msg = MIMEText(content, _charset='utf8')
        msg['Subject'] = subject
        msg['From'] = self._msg_from
        msg['To'] = msg_to
        self._smtp.sendmail(self._msg_from, msg_to, msg.as_string())


if __name__ == "__main__":
    qq_mail_client = QQMailClient ( '[email protected] ' , ' uralqflhwgbhbfxx ' )
    qq_mail_client.send_mail( ' [email protected] ' , ' test subject ' , ' test content ' )

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325025741&siteId=291194637