我使用一個應用程序與發送電子郵件給用戶進行通知。但在應用setting.py文件包含的Django發送電子郵件混亂
設置文件
EMAIL_USE_TLS = True
一些容易混淆的術語如 我不知道這是什麼,也
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
什麼就是在這兩年
的品種,如果主機是d在此
mailUsr = "[email protected]" ???? what's this for ?
這裏eclared然後
mail.py
def send_mail(title,message,reciver):
try:
mailS = 'smtp.gmail.com'
mailP = 587
mailUsr = "[email protected]"
mailPass = "********"
# Create a text/plain message
msg = MIMEMultipart('alternative')
msg['Subject'] = title
msg['From'] = mailUsr
msg['To'] = reciver
html="<html><head></head><body><p>"+message.replace("\n","<br>")+"</p></body></html>"
part2 = MIMEText(html, 'html')
msg.attach(part2)
# Send the message via our own SMTP server, but don't include the
s = smtplib.SMTP(mailS,mailP)
s.ehlo()
s.starttls()
s.ehlo()
s.login(mailUsr,mailPass)
s.sendmail(mailUsr, [reciver], msg.as_string())
s.quit()
except Exception as e:
print(e)
我是新來這。這讓我感到困惑。 謝謝你。
也許你應該花幾分鐘閱讀相關的電子郵件Django文檔頁面:https://開頭的文檔.djangoproject.com/en/1.11/topics/email/ – Antwane