[Django] #33438: SMTPAuthenticationError in EmailMessage and EmailMultiAlternatives when using 'Some Name <email@gmail.com>' format for `from_email` while running server locally

5 views
Skip to first unread message

Django

unread,
Jan 13, 2022, 7:03:15 AM1/13/22
to django-...@googlegroups.com
#33438: SMTPAuthenticationError in EmailMessage and EmailMultiAlternatives when
using 'Some Name <em...@gmail.com>' format for `from_email` while running
server locally
-------------------------------------+-------------------------------------
Reporter: Avramo | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Core | Version: 2.2
(Mail) | Keywords: EmailMessage,
Severity: Normal | SMTPAuthenticationError,
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Here are my configuations:

''.env''
{{{
EMAIL_HOST_USER = 'ma...@gmail.com'
}}}


''settings.py
''
{{{
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
}}}


This works just fine normally.

My issue is when I want to add a name to ''from_email'' using the accepted
format:[https://docs.djangoproject.com/en/4.0/topics/email/#emailmessage-
objects]
ie: "Customer Service <fr...@fred.com>" so the recipient sees 'Customer
Service' instead of just 'fred' or fred@... like this:

{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
email = EmailMultiAlternatives(
subject='subject msg',
body='testing',
from_email=f'Customer Service <{settings.EMAIL_HOST_USER}>',
to=[request.user.email],
)
email.attach_alternative(render_to_string('Campaign_Email_NEW.html'),
"text/html")
email.send()
}}}
}}}

I tired this in the shell of my live server and it worked!

BUT when I tried to run this in the shell or via postman when running the
server locally on my computer then I get a SMTPAuthenticationError, with
this info:

{{{
Exception Type: SMTPAuthenticationError at /api/campaign_mail/
Exception Value: (535, b'5.7.8 Username and Password not accepted. Learn
more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials
i3sm1161703wrn.11 - gsmtp')
}}}

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

Django

unread,
Jan 13, 2022, 7:06:45 AM1/13/22
to django-...@googlegroups.com
#33438: SMTPAuthenticationError in EmailMessage and EmailMultiAlternatives when
using 'Some Name <em...@gmail.com>' format for `from_email` while running
server locally
-------------------------------------+-------------------------------------
Reporter: Avramo | Owner: nobody
Type: Uncategorized | Status: closed
Component: Core (Mail) | Version: 2.2
Severity: Normal | Resolution: duplicate
Keywords: EmailMessage, | Triage Stage:
SMTPAuthenticationError, | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Avramo):

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


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

Reply all
Reply to author
Forward
0 new messages