Python3發送郵件功能


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)

都是固定的模版,可以套用, 不用硬記。   最后發送結果 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM