使用163smtp發送郵件


import smtplib
from email.mime.text import MIMEText

mail_host = 'smtp.163.com'
mail_user = '發件人郵箱'
mail_pwd = '授權碼'

sender = '發件人郵箱'
receivers = ['收件人郵箱']

content = 'python使用163smtp發送郵件'
title = '人生苦短'


def sendmail():
    message = MIMEText(content, 'plain', 'utf-8')  # 內容,格式,編碼
    message['From'] = "{}".format(sender)
    message['To'] = ','.join(receivers)
    message['Subject'] = title
    try:
        smtpobj = smtplib.SMTP_SSL(mail_host, 465)  # 啟用SSL發信,端口一般是465
        smtpobj.login(mail_user, mail_pwd)  # 登陸驗證
        smtpobj.sendmail(sender, receivers, message.as_string())
        print('mail has been send successfully')
    except Exception as e:
        print(e)


sendmail()

 


免責聲明!

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



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