天天看點

python django 中利用QQ郵箱進行郵件發送,可用于郵箱注冊、忘記密碼

配置:

windows10

python3.5   django1.11.7

編碼過程中需要利用django中自帶的mail子產品,位于django.core.mail路徑,引入send_email方法:

from django.core.mial import send_email
           

setting.py 檔案的參數配置:

EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = '[email protected]' # 登陸第三方的郵箱賬号
EMAIL_HOST_PASSWORD = '第三方登陸的授權碼'
EMAIL_USE_TLS = True  # 必須配置為true
EMAIL_FROM = '[email protected]'  # 主動發送的郵箱
           

在View中調用send_email()方法:

send_status = send_mail('郵件主題', '郵件内容', '發送者', [email, '收件人清單'])
           

新浪郵箱注冊更為簡單,可參照:https://www.jianshu.com/p/5c30ff053381