[Django] #28922: django.core.mail.send_mail() is not using settings values

4 views
Skip to first unread message

Django

unread,
Dec 13, 2017, 7:03:05 PM12/13/17
to django-...@googlegroups.com
#28922: django.core.mail.send_mail() is not using settings values
----------------------------------------+------------------------
Reporter: Zach Bresser | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 2.0
Severity: Normal | Keywords: Mail
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28922>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 14, 2017, 2:26:42 AM12/14/17
to django-...@googlegroups.com
#28922: django.core.mail.send_mail() is not using settings values
------------------------------+--------------------------------------

Reporter: Zach Bresser | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:

Keywords: Mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Simon Charette):

Hello there, I unfortunately cannot reproduce your issue against Django
2.0 and we've got
[https://github.com/django/django/blob/6fd6d8383f48ea2fe4e058725fa30529a083e9a5/tests/mail/tests.py#L1265-L1287
unit tests asserting settings fallbacks] work correctly.

Unless you're able to provide a reduced test case to help us reproduce
your issue I'm afraid we'll have to close this ticket as ''worksforme''.

--
Ticket URL: <https://code.djangoproject.com/ticket/28922#comment:1>

Django

unread,
Dec 14, 2017, 2:33:20 PM12/14/17
to django-...@googlegroups.com
#28922: django.core.mail.send_mail() is not using settings values
------------------------------+--------------------------------------

Reporter: Zach Bresser | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution: worksforme

Keywords: Mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => worksforme


--
Ticket URL: <https://code.djangoproject.com/ticket/28922#comment:2>

Django

unread,
Dec 14, 2017, 2:43:48 PM12/14/17
to django-...@googlegroups.com
#28922: django.core.mail.send_mail() is not using settings values
------------------------------+--------------------------------------

Reporter: Zach Bresser | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution: worksforme

Keywords: Mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Zach Bresser):

Can we reopen this? At least in my case it was not falling back to the
settings variables.

I am working on getting a test case together for Simon. I work full time
so I have been unable to do it today.

--
Ticket URL: <https://code.djangoproject.com/ticket/28922#comment:3>

Django

unread,
Dec 14, 2017, 2:50:20 PM12/14/17
to django-...@googlegroups.com
#28922: django.core.mail.send_mail() is not using settings values
------------------------------+--------------------------------------

Reporter: Zach Bresser | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution: worksforme

Keywords: Mail | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Simon Charette):

Zach, feel free to re-open the ticket if you can provide a simplified
reproduction test case.

--
Ticket URL: <https://code.djangoproject.com/ticket/28922#comment:4>

Reply all
Reply to author
Forward
0 new messages