Django 不通过 gmail 发送电子邮件

Ksh*_*ari 0 python django

我正在尝试建立一个在线书店,并且我正在尝试向新签名的用户发送一封验证电子邮件,但由于某种原因没有发送电子邮件,我还尝试在 gmail 中使用特定于应用程序的密码。

将不胜感激。

这是我在 settings.py 中的电子邮件代码

EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_HOST_USER='kshitu.rangari@gmail.com'
EMAIL_HOST_PASSWORD='jgpcjiajvklxraof'
EMAIL_PORT=587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'books@pickabook.com'
Run Code Online (Sandbox Code Playgroud)

我的 Views.py 中的代码

from .models import Book

def index (request):
    return render (request,'template.html')

def store (request):
    return render (request, 'store.html' )

def store (request):
    count = Book.objects.all().count()
    context = {
        'count':count,
    }
    return render (request,'store.html',context)
Run Code Online (Sandbox Code Playgroud)

Abi*_* Mg 5

由于您已经准备好电子邮件设置并测试是否正在发送电子邮件,请执行以下操作

  1. 在settings.py中

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

  1. 运行交互模式, python manage.py shell

  2. 导入 EmailMessage 模块, from django.core.mail import EmailMessage

  3. 发送电子邮件,

email = EmailMessage('Subject', 'Body', to=['kshitu.rangari@gmail.com']) email.send()

如果上述操作成功,则您的 Gmail 帐户已配置为发送电子邮件。