Table of Contents
This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Ir a: Repositorio, Formularios, Api Form
Envio de Mails
Libreria core.mail
settings.py
EMAIL_BACKEND = 'django.core.imail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 'ejemplo@gmail.com'
EMAIL_HOST_PASSWORD = 'clave-ejemplo'
settings-doc django.core.mail-doc
🔸️python3 manage.py shell
(InteractiveConsole)
>>> from django.core.mail import send_mail
>>>
>>> send_mail('Test Django Admin',
'Mensaje desde la consola de django',
'webmaster@django.net',
['destinatario@mail.com'],
fail_silently = False,
)
Envio de mail desde formulario de contacto
views.py
...
from django.core.mail import send_mail
from django.conf import settings
...
def contacto(request):
if request.method == "POST":
subject = request.POST['asunto']
message = request.POST['mensaje']+' '+request.POST['email']
email_from = settings.EMAIL_HOST_USER
recipient_list = ['ratablastard@gmail.com']
send_mail(subject, message, email_from, recipient_list)
return render(request, "gracias.html")
return render(request, "contacto.html")
Ir a: Repositorio, Formularios, Api Form