1

I'm following along with this book and in chapter 18 part of the current assignment involves sending an email via Django. I have a yearly domain I use for testing, and rather than pay an additional 5$ a month I figured I'd just have the emails forwarded to an existing address, using these instructions.

I then went ahead and set it up so I could send mail using an alias via the Sending mail from your forwarded email address section

However, I'm unable to get it working using the generated app password + alias. When I try to send an email from the page it only works if 2FA is disabled and I use my actual gmail credentials, say for example:

EMAIL_HOST_USER = 'bob@gmail.com'
EMAIL_HOST_PASSWORD = 'bobswife123'

It works as intended. However, lets say I wanted to use my generated app password and alias, something like:

EMAIL_HOST_USER = 'alias@bob.com'
EMAIL_HOST_PASSWORD = 'bobsmistress123'

Then I'll get the following error:

SMTPAuthenticationError at /accounts/send_email

Was not able to make any use of the support article from the URL in the above screenshot, but here it is for the sake of convenience:

https://support.google.com/mail/?p=BadCredentials

Anyways, these are the exact steps I'm taking:

From terminal on macOS 10.13.1, I run python manage.py runserver from terminal, and then enter http://localhost:8000/ into Google Chrome. The page displays correctly. I hit enter and try to send the email. Next, it either works, or I get the screenshot shown above. Here's a dpaste of the traceback:

http://dpaste.com/2DVFSPK

other potentially relevant settings:

EMAIL_HOST = 'smtp.gmail.com
EMAIL_PORT = 465
EMAIL_USE_SSL = True

Any help is greatly appreciated!

Regarding the duplication accusation:

I have already tried the accepted answer's instructions from the potential duplicate. Once again, I can get this to work by using my normal Gmail credentials -- but I don't want to reveal my personal email address, which is why I setup an alias using these instructions. This should allow me to send emails on behalf of the alias domain (which I own)

Edit: Adding my response to user inquiring whether I tried the troubleshooting steps (tl;dr yes i did):

  • Update your email client to the latest version.
    Not using an email client for this; not applicable
  • Use an App Password: If you use 2-Step Verification, try signing in with an App Password.
    Already addressed this above; kinda what my issue is about
  • Allow less secure apps: If you don't use 2-Step Verification, you might need to allow less secure apps to access your account.
    Allow less secure apps is already enabled. Doesn't work otherwise
  • If you recently changed your Gmail password, you might need to re-enter your Gmail account information or completely repeat your Gmail account setup on your other email client.
    Not related to my gmail password -- it works when I use my actual gmail credentials and I'm able to login to gmail
  • If the tips above didn't help, visit https://www.google.com/accounts/DisplayUnlockCaptcha and follow the steps on the page.
    Already tried this
  • The email client's sign-in method might be insecure. Try signing in directly on the Gmail app.
    Don't think I can use the gmail app in combination with this; not applicable
Dharman
  • 30,962
  • 25
  • 85
  • 135
kt-0
  • 357
  • 3
  • 10
  • Have you tried the troubleshooting steps listed in that help article? I'm pretty sure your issue will be with one of those - most likely the "less secure apps" bit. – solarissmoke Dec 16 '17 at 03:56
  • Possible duplicate of [Django SMTPAuthenticationError](https://stackoverflow.com/questions/26697565/django-smtpauthenticationerror) – solarissmoke Dec 16 '17 at 03:57

1 Answers1

1

I encountered the same issue: I got it working by using different email addresses for login and sendmail (i.e. Login with gmail account and app password,then specify the forwarded email as sender in sendmail).

For example:

smtpObj.login('bob@gmail.com', 'bobsmistress123')
smtpObj.sendmail('alias@bob.com', receiver, emailString)
toshiro92
  • 1,287
  • 5
  • 28
  • 42
  • 1
    Can't edit because it's too few characters so I'm not allowed. But you should add a newline for your code to be correctly formatted :) – totooooo Mar 28 '20 at 18:49