Hello, I have a paid account, and I have been trying to send a simple test mail. I'm using a paid account in hostinger for the mail
In my settings.py I have (inside my app folder) (edit.- note that I have a typo in EMAIL_BAKEND, it should be EMAIL_BACKEND)
# Email settings, from pylessons/django-email-confirm and some AI help from hostinger
EMAIL_BAKEND = "django.core.mail.backeneds.smtp.EmailBackend"
EMAIL_HOST = "smtp.hostinger.com"
EMAIL_FROM = "my_mail"
EMAIL_HOST_USER = "my_mail"
EMAIL_HOST_PASSWORD = "my_secret_pass"
EMAIL_PORT = 587 # according to hostinger mail (465) (587 in other examples)
EMAIL_USE_TLS = True
I'm calling these setting in my views with:
from . import settings
And I'm also using:
from django.core.mail import send_mail
This is my view that is taking care of rendering my subscribe page, that is right now really simple, I do have a form for this, and also a model for the db, that I'm currently not using (my program gets always to the object does not exist exception), and before sending the mail it is throwing me the ConnectionRefusedError.
def subscribe(request):
print(f"checking if this works {settings.EMAIL_HOST_USER}")
if request.method == "POST":
subs_form = SubsForm(request.POST)
if subs_form.is_valid():
nombre_subs = request.POST["nombre"]
apellidos_subs = request.POST["apellidos"]
correo_subs = request.POST["correo"]
try:
subs_guy = Correo.objects.get(nombre = nombre_subs, apellidos = apellidos_subs, correo = correo_subs)
if subs_guy.conf_mail_sent == True and subs_guy.confirmado == False:
messages.warning(request, f"Ya se envió un correo de confirmación a {subs_guy.correo}, pero no se ha activado, revisar en inbox o spam")
elif subs_guy.conf_mail_sent == True and subs_guy.confirmado == True:
messages.warning(request, f"{subs_guy.nombre} {subs_guy.apellidos} está registrado con el correo {subs_guy.correo}")
except ObjectDoesNotExist:
messages.warning(request, f"Correo inexistente, se acaba de mandar un correo de confirmación a {correo_subs}, por favor, revise su correo.")
send_mail(
"subject_test",
"mssg_test",
settings.EMAIL_HOST_USER,
[correo_subs],
fail_silently = False
)
else:
messages.warning(request, "Hay un problema con los datos")
subs_form = SubsForm()
return render(request, "vibramur/subscribe.html", {
"form": subs_form
})
else:
subs_form = SubsForm()
return render(request, "vibramur/subscribe.html", {
"form": subs_form
})
This is my first time trying to send an e-mail though Django, I don't know if I'm messing up somewhere, any help would be appreciated