I have a simple django application and that I can't seem to get to send emails. In my settings file I have:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'MyHost@gmail.com'
EMAIL_HOST_PASSWORD = 'Mypassword'
DEFAULT_FROM_EMAIL = 'From Email'
The above values are just placeholders, I have the correct values in my settings.
The code for sending an email on model creation:
@receiver(post_save, sender = Alerta)
def my_callback(sender, created, **kwargs):
if created:
from_email = settings.DEFAULT_FROM_EMAIL
print(from_email)
try:
send_mail(
'Fogo Florestal',
"Mensagem",
from_email,
["some_destination@gmail.com"],
fail_silently=False,
)
except Exception as e:
print(e)
I also made sure that the Gmail account I am using can be used by less secure apps. Moreover when the email is not sent no exception is printed to the terminal
I have another web app which uses the the same send email procedure and it works properly.
Has anyone faced a similar problem? I am using python 3.5 and django 2.1