﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28922	django.core.mail.send_mail() is not using settings values	Zach Bresser	nobody	"Hello, I have found a bug in django.core.mail.send_mail()

I previously had the following SETTINGS:

{{{
# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp-relay.gmail.com'
EMAIL_HOST_USER = 'my_user'
EMAIL_HOST_PASS = 'my_pass
EMAIL_PORT = 587
EMAIL_USE_TLS = True
}}}

and the following view:


{{{
def index(request):
    """""" Return landing page with contact form """"""

    if request.method == 'GET':
        # Init a blank form
        form = ContactForm()
    else:
        # Grab data from POST, validate, and attempt to send mail.
        form = ContactForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            from_email = form.cleaned_data['from_email']
            message = form.cleaned_data['message']
            try:
                send_mail(subject, message, from_email, [my_to_email])
            except BadHeaderError:
                # Fail on invalid header.
                return HttpResponse('Invalid Header found.')
            # After sending, redirect to /success
            return redirect('success/')
        # return blank form
    return render(request, 'index.html', {'form': form})
}}}

Which are all correct (I'm using gsuite so I use smtp-relay.gmail.com instead of smtp.gmail.com).

I spent hours working on it, even tried sendgrid, was getting Unauthenticated Senders Not Allowed, and contacted their support and none of us were able to get it to work. 

Finally I tried explicitly setting auth_user and auth_pass in send_mail(), and it finally worked.

After importing setting variables: 


{{{
send_mail(subject, message, from_email, ['my_to_address'],
                          auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASS)
}}}

This makes it seem like it is not falling back to the settings variables. I attempted to diagnose the issue, but was unable to. I hope someone else can solve where it needs to be set. "	Bug	closed	Core (Other)	2.0	Normal	worksforme	Mail		Unreviewed	0	0	0	0	0	0
