I have a problem the form works but it does not send me the emails could you help me It is my first publication,
I have a problem the form works but it does not send me the emails could you help me It is my first publication, I honestly have no idea what it could be
[CODE SETTINGS]
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_USE_TLS=True
EMAIL_PORT=587
EMAIL_HOST_USER='xxxxx@gmail.com'
EMAIL_HOST_PASSWORD='xxxxxxxxxxxxxxxxx'**
[** CODE VIEWS **]
from django.shortcuts import render, redirect
from .forms import FormularioContacto
from django.conf import settings
from django.core.mail import EmailMessage
# Create your views here.
def contacto(request):
form=FormularioContacto()
if request.method == "POST":
form=FormularioContacto(data=request.POST)
if form.is_valid():
nombre=request.POST.get("nombre")
email=request.POST.get("email")
contenido=request.POST.get("contenido")
email= EmailMessage(f"Alguien quiere contactarse desde la WEB,El Usuario: {nombre} con el email: {email} por el asunto: {contenido}","",["torresfdev@gmail.com"],reply_to=[email])
email.send()
try:
return redirect("/contacto/?Enviadoconexito")
except:
return redirect ("/contacto/?NO_se_pudo_enviar")
return render (request,"contactoapp/contacto.html", {"form":form})
I think you are using the wrong email function
in django email documentation, they recommend using send_mail
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from@example.com',
['to@example.com'],
fail_silently=False,
)
and also check if your gmail account allows access to less secured apps (less secured app access in gmail)