Django不通过Gmail发送电子邮件

时间:2017-03-08 19:25:07

标签: 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'

我的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)

2 个答案:

答案 0 :(得分:2)

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

  1. 在settings.py make
  2. 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. 发送电子邮件

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

      如果上述方法成功,那么您的Gmail帐户将配置为发送电子邮件。

答案 1 :(得分:0)

对于Gmail,您可能需要在Google帐户中切换“启用安全性较低的应用”功能。

https://support.google.com/accounts/answer/6010255?hl=en

相关问题