Reputation: 716
I'm trying to get django to send an email but I get as a return in my terminal the print from my else that says there was a problem and it wasn't sent. Why is this happening?
This is the code with the email:
from django.core.mail import EmailMultiAlternatives
from . import views
def constancia_email(email):
subject, from_email, to = 'Constancia Monotributo', '[email protected]', email
text_content = 'Hi, this is your pfd.'
html_content = '<p><strong>Hi!</strong></p> <p>This is your pdf</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
attachment = open('constancia.pdf', 'rb')
msg.attach('constancia.pdf', attachment.read(), 'text/pdf')
msg.content_subtype = 'html'
msg.attach_alternative(html_content, "text/html")
msg.send()
This is the view part with the email:
#send email
constancia_email(email)
if constancia_email == True:
print("Sus datos fueron enviados correctamente, en un máximo de 2 hs. estarás recibiendo tu constancia por email.")
else:
print("No hemos podido procesar su solicitud, por favor reintente nuevamente más tarde.")
I added this to my settings because I was getting an error but I'm not sure if this helps because I just get the email in my console but it still isn't sent:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Upvotes: 1
Views: 534
Reputation: 850
:). Everything works as expected, doesn't it? The email console backend is not sending emails anywhere, it just displays them in the console.
PS: If you feel that you are ready to send your emails to outside world, use EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
Upvotes: 1