[Answer]-What is the proper way to set the "From" header in an email using Django EmailMessage class?

1👍

You can put the details directly in the from argument:

email = EmailMessage(
    'My foobar subject!!',
    body,
    'Darth Vader <notify@foobar.com>',
    [the_user.email])

0👍

email = EmailMessage(
    'My foobar subject!!',
    render_to_string(
        'emails/new_foobar_email.txt',
        {
            'foo': foo.something,
            'bar': bar.something,
        }
    ),
    'darth@vader.com',
    [the_user.email, ],
    headers={'From': 'Darth Vader <darth@vader.com>'},
)
email.send(
    fail_silently=False
)

The key thing I did wrong was having a trailing space after “From”. So this will work.

However. I’m going to simplify the code and do as @Daniel Roseman suggested and put the display name in the from argument and not use the headers key words.

Leave a comment