diff --git a/5_Envio_de_mails.md b/5_Envio_de_mails.md index 566f8e5..a1c6ea9 100644 --- a/5_Envio_de_mails.md +++ b/5_Envio_de_mails.md @@ -6,4 +6,47 @@ ## Envio de Mails -### \ No newline at end of file +### 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](https://docs.djangoproject.com/en/dev/ref/settings/#email-host) +[django.core.mail-doc](https://docs.djangoproject.com/en/3.0/topics/email/#module-django.core.mail) + +🔸️***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, + ) +``` + +*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") +```