python3關於郵件的操做

話很少說,上代碼測試

import smtplib
from email.mime.text import MIMEText   # 導入模塊

class SendEmail:

    def send_emil(self, username, passwd, recv, title, content, mail_host='smtp.163.com', port=25):
        msg = MIMEText(content)      #郵件內容
        msg['Subject'] = title
        msg['From'] = username
        msg['To'] = recv
        smtp = smtplib.SMTP(mail_host, port=port)   # 定義郵箱服務類型
        smtp.login(username, passwd)      # 登陸郵箱
        smtp.sendmail(username, recv, msg.as_string())   #發送郵件
        smtp.quit()
        print('email 發送成功.')

if __name__ == '__main__':
    email_user = '1326*****@163.com'  # 發送者帳號
    email_pwd = '******'  # 發送者密碼,受權碼
    maillist = '5****@qq.com'   # 接收者郵箱
    title = '測試郵件標題'
    content = '這裏是郵件內容'
    SendEmail().send_emil(email_user, email_pwd, maillist, title, content)
相關文章
相關標籤/搜索