Opened 3 years ago

Closed 3 years ago

#33498 closed Uncategorized (needsinfo)

Email FROM: field unusual behavior of changing the input, can lead to errors

Reported by: Michael Owned by: nobody
Component: Core (Mail) Version: 4.0
Severity: Normal Keywords: email
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Michael)

This code will generate a 500 error instead of sending an email about the 404 error (the problem is the FROM field). It's a hard to error to find due to no stack trace, had to binary search a lot of code to find it (cause it works fine with console email backend (i.e during dev)):

    from django.core.mail import send_mail

    send_mail(
        f'Suspicious file requested from {client_ip} for {path}',
        f'Suspicious file requested from {client_ip}.\nURL: {absolute_url}',
        '"Notifications" <error@example.com>',
        [Cfg.EMAIL_SUPPORT],
        fail_silently=True,
    )

If one emoves the double quotes:

    send_mail(
        f'Suspicious file requested from {client_ip} for {path}',
        f'Suspicious file requested from {client_ip}.\nURL: {absolute_url}',
        'Notifications <error@example.com>',
        [Cfg.EMAIL_SUPPORT],
        fail_silently=True,
    )

Then the from field in gmail is:

	'Notifications' via support <support@example.com>

Which is not what it was set to. The person's name was set to Notifications not 'Notifications' via support, and the from email address was set to error@example.com not support@example.com

This is my settings.py:

SERVER_EMAIL = f'support@example.com'  # The reply to
DEFAULT_FROM_EMAIL = somebody@example.com'
ADMINS = [('Support', 'support@example.com')]
MANAGERS = ADMINS
EMAIL_SUBJECT_PREFIX = "Example Server: "

THe documentation says:

from_email: A string. If None, Django will use the value of the DEFAULT_FROM_EMAIL setting.

It does not specify this unusual behavior.

Change History (2)

comment:1 by Michael, 3 years ago

Description: modified (diff)
Summary: Email TO: field unusual behavior of changing the input, can lead to errorsEmail FROM: field unusual behavior of changing the input, can lead to errors

comment:2 by Tim Graham, 3 years ago

Resolution: needsinfo
Status: newclosed

I'd guess this is a behavior of your mail server rather than Django. You should debug further and reopen this ticket if you find that Django is at fault.

Note: See TracTickets for help on using tickets.
Back to Top