I'm trying to send an e-mail from django app in docker on Ubuntu and I'm receiving following message:
Request Method: GET
Request URL: https://localhost:8001/accounts/mail/
Django Version: 2.2.5
Exception Type: SMTPAuthenticationError
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 x76sm1225174ljb.81 - gsmtp')
Exception Location: /usr/local/lib/python3.7/smtplib.py in auth, line 642
Python Executable: /usr/local/bin/python
Python Version: 3.7.4
There is no problem to send an e-mail outside docker.
I tried every step from Google troubleshooting steps. Currently I have 2-Step verification which works for local app but still doesn't for docker one.
I don't necessarily need Google SMTP (I have an account there), but what I what to achive is to send e-mail with activation link to user after registration for django application.
I tried without 2-factor auth - the same result. My docker-compose settings in web service:
services:
web:
build: ./app
command: python manage.py runsslserver 0.0.0.0:8001
stdin_open: true
tty: true
volumes:
- ./app/:/usr/src/app/
- /etc/localtime:/etc/localtime
- /etc/timezone:/etc/timezone
ports:
- 8001:8001
- 587:587
- 25:25
- 465:465
And code to send an e-mail (works outside the docker):
def email(request):
mail_subject = 'Activate your account'
message = 'test'
to_email = 'example@example.com'
email = EmailMessage(
mail_subject, message, to=[to_email]
)
email.send()
return redirect('index')
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'example@example.com'
EMAIL_HOST_PASSWORD = '***'
EMAIL_PORT = 587