Mail is not sent in django help no se envia mail en django

I try to get an email from my page that I made in django, but it doesn't, I did if it was sent, tell me that it was sent correctly, and if it was not sent, it would redirect me to the same page. The problem is that it is never sent correctly, as if something was wrong directly when I coded the view or something like that. the problem is that it is never sent. the POST is never sent.

Views.py

from django.shortcuts import render , redirect   
from .forms import FormularioContacto
from django.core.mail import EmailMessage


# Create your views here.


def contacto(request):

    formulario_contacto=FormularioContacto()

    if request.method == "POST":
        formulario_contacto=FormularioContacto(data=request.POST)
        if formulario_contacto.is_valid():
            nombre= request.POST.get("nombre")
            email= request.POST.get("email")
            numero= request.POST.get("numero")
            contenido= request.POST.get("contenido")


            email=EmailMessage("mensaje desde app django",
             "el usuario con el nombre: {} con la direccion: {} y el numero: {} te escribe: \n\n {}".format(nombre, email, numero, contenido),
            "", ["faustofernandezes@gmail.com"], reply_to=[email])

            try:
                email.send()

                return redirect("/contacto/?valido")

            except:
                 return redirect("/contacto/?novalido")


    return render(request, "contacto/contacto.html" , {'miFormulario' : formulario_contacto})

settings:

STATIC_URL = '/static/'
MEDIA_URL='/media/'
MEDIA_ROOT=BASE_DIR / 'media'

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

#config de mail

EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST="smtp.gmail.com"
EMAIL_USE_TSL=True
EMAIL_PORT=587
EMAIL_HOST_USER="faustofernandezes@gmail.com"
EMAIL_HOST_PASSWORD="Here I put my 2-step verification application password"

html:


    {% extends "ProyectoApp/base.html" %}

    {% load static %}
    
    {% block content %}
   <div class="contenedorFormulario">

      {% if "valido" in request.GET %}

           <p style="color: white;">informacion enviada correctamente!!  <br> Gracias por contactar!!   </p>

      {% endif %}

    <form action="" method="POST" style="text-align: center;" > {% csrf_token %} 
        
    
        <table style="color: white; margin: 20px auto;" >{{miFormulario.as_table}}</table>
        <input type="submit" value="Enviar" style="width: 150px;">

    </form>
    
    </div>

    {% endblock %}

forms:

from django import forms

class FormularioContacto(forms.Form):

    nombre=forms.CharField(label="Nombre", required=True, max_length=150)
    email=forms.CharField(label="Email", max_length=50 , required=True)
    contenido=forms.CharField(label="Contenido", widget=forms.Textarea )

Also try trying to write everything again with send_mail, importing from django.core.mail import send_mail. but it didn't work either, I don't know what the problem would be in this code, I hope someone can help me since I'm doing a course and it's very difficult for me to continue like this. I would really be very grateful. Thank you for your attention.

Back to Top