gpt4 book ai didi

django - 如何在 Django 中发送电子邮件

转载 作者:行者123 更新时间:2023-12-04 10:44:23 26 4
gpt4 key购买 nike

我有setting.py

# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'pass'
EMAIL_PORT = 587

和电子邮件方法在 admin.py
send_mail(
'Subject here',
'Here is the message.',
'from@gmail.com',
['to@gmail.com'],
fail_silently=False,
)

但它给出了错误 SMTP AUTH extension not supported by server.我如何解决这个问题,在本地主机上工作

最佳答案

尝试创建一个像这样的自定义发送电子邮件文件

import smtplib
from email.message import EmailMessage

# Send Email Function
def send(to):
email = EmailMessage()
email['from'] = 'Test'
email['to'] = to
email['subject'] = 'Hello World'

with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login('user', 'password')
smtp.send_message(email)

关于django - 如何在 Django 中发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59777016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com