我没有从联系表格中收到电子邮件

时间:2019-03-01 03:40:37

标签: django django-models

伙计们,我正在尝试使用django 2.1填写联系表格,它将通过发件人向我发送电子邮件,但我不知道为什么,没有向我发送我应该收到的电子邮件

views.py

def index(request):
  queryset = Post.objects.filter(featured = True)

  if request.method == 'POST':
    name = request.POST.get('name')
    email = request.POST.get('email')
    subject = request.POST.get('subject')
    message = request.POST.get('message')

    subject = 'Message from ubaidparvaiz.com recieved'
    from_email = settings.DEFAULT_FROM_EMAIL
    to_email = [settings.DEFAULT_FROM_EMAIL]
    context = {'user':name,
               'email':email,
               'message':message,
               'subject':subject
               }


    contact_message = get_template('app/contact_message.txt').render(context)

    send_mail(subject,message,from_email,to_email,fail_silently = True)

    return redirect('index')



  return render(request,'app/index.html',{'object':queryset})

settings.py

SEND_GRID_API_KEY = 'API key'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'ubaidparvaiz'
EMAIL_HOST_PASSWORD = '.py/r^admin1'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'ubaidparvez4@gmail.com'
ACCOUNT_EMAIL_SUBJECT_PREFIX = 'Contact email received from my blog'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

contact_message.txt

You recieved a message,Don,t panic ..Keep it normal

The sender,s name : {{user}}

They sender,s email : {{email}}

The sender,s subject : {{subject}}

This is what he states : {{message}}

谢谢

1 个答案:

答案 0 :(得分:0)

我建议您检查垃圾邮件文件夹。 Gmail通常会过滤来自不受信任来源的电子邮件。