-1

I have an app that sends out an email when an object is create, this is the code for sending email:

from django.core.mail import send_mail    
send_mail("New entryis added", "Hi a new entry is added", "myemail@gmail.com", [c.email for c in CustomUser.objects.all()], fail_silently=False)

and this is my setting:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

I also made sure that my "Less secure app access" is on in google security setting. So with all thses I am able to send email with no issue in local server. However when I push the code to digital ocean droplet linux server, it throws some errors:

SMTPAuthenticationError at /a/b/c/add/

(534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu\n5.7.14 VVGrAjSoYzu_W9fGpWsq5B3qMs04qWLzeqnxkFdrMaeVJumRRljQzXEyYpA9xt1MSYaii\n5.7.14 iyVCj2qaXbQzY5Tvc3mux9qViJSKE5yOozpCzao_qU0FhjYGX8IZ1xgd9PUep41I>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 g9sm2079574pgj.89 - gsmtp')

Exception Type:     SMTPAuthenticationError

I apreciate if someone can shed some light on what is the issue, Thanks,

Nabat Farsi
  • 840
  • 1
  • 9
  • 17
  • You've shown how you're trying to call send_mail() function.. please include send_mail() definition as well.. – Ronnie Apr 10 '20 at 18:33
  • 1
    @Ronnie Thats the standard send mail method from django.core.mail. The definition for it is in the Django docs. – dfundako Apr 10 '20 at 18:39

2 Answers2

0

One thing I have used to fix this is to put the TLS variable first. Put this above all the other settings.

EMAIL_USE_TLS = True

Try this to help diagnose it. You can send emails from the Django shell, so ssh into your server and try this.

>>> from django.core.mail import send_mail
>>> send_mail('test email', 'hello world', 'myemail@gmail.com', ['your@email.com'])

Test to see if this is more informative.

Matthew Gaiser
  • 4,558
  • 1
  • 18
  • 35