我使用一个应用程序与发送电子邮件给用户进行通知。但在应用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