Closed AdrienLemaire closed 6 years ago
I've been trying to write a simple view to send emails, but I keep getting 0 as result from send_mail
''' Backend views ''' from smtplib import SMTPException from django.http import JsonResponse from django.core.mail import send_mail from django.template.loader import render_to_string from django.conf import settings from django.views.decorators.http import require_POST from django.views.decorators.csrf import csrf_exempt @require_POST @csrf_exempt def contact_email(request): ''' Send an email to the user when he press the contact form ''' email = request.POST.get('email') subject = 'Subject' message = '' # Using html message instead html_message = render_to_string('email.html', {'email': email}) from_email = settings.DEFAULT_FROM_EMAIL try: result = send_mail(subject, message, from_email, [email], html_message=html_message, fail_silently=False) if result == 0: return JsonResponse({ 'status': 'error', 'errorMessage': 'Could not send email', }, status=400) return JsonResponse({ 'status': 'success' }, status=200) except SMTPException: return JsonResponse({ 'status': 'error', 'errorMessage': 'Could not send email', }, status=400)
Might you have any idea as to why it happens, and how to debug this issue ?
stupid me, wasn't doing the curl query correctly when testing it :)
I've been trying to write a simple view to send emails, but I keep getting 0 as result from send_mail
Might you have any idea as to why it happens, and how to debug this issue ?