Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django send_mail not working

When the view that sends the email is used nothing happens, i then entered send_mail(...) into the python shell and it returned 1 but i didn't receive any emails.

This is my settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'P@ssw0rd5'
EMAIL_USE_TLS = True

This is the view:

def send_email(request):
    send_mail('Request Callback', 'Here is the message.', '[email protected]',
        ['[email protected]'], fail_silently=False)
    return HttpResponseRedirect('/')
like image 516
CJ4 Avatar asked Apr 30 '12 13:04

CJ4


1 Answers

Adjust your settings thus:

DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'P@ssw0rd5'

Adjust your code:

from django.core.mail import EmailMessage

def send_email(request):
    msg = EmailMessage('Request Callback',
                       'Here is the message.', to=['[email protected]'])
    msg.send()
    return HttpResponseRedirect('/')
like image 121
Burhan Khalid Avatar answered Sep 20 '22 18:09

Burhan Khalid