我有setting.py
# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4e464a42476b4c464a424705484446" rel="noreferrer noopener nofollow">[email protected]</a>'
EMAIL_HOST_PASSWORD = 'pass'
EMAIL_PORT = 587
电子邮件方法在 admin.py 中
send_mail(
'Subject here',
'Here is the message.',
'<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f697d60624f68626e6663216c6062" rel="noreferrer noopener nofollow">[email protected]</a>',
['<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="087c67486f65696164266b6765" rel="noreferrer noopener nofollow">[email protected]</a>'],
fail_silently=False,
)
但它给出了错误
服务器不支持 SMTP AUTH 扩展。
我如何解决这个问题,在本地主机上工作
最佳答案
尝试创建一个像这样的自定义发送电子邮件文件
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/