fin vid25
parent
516aec1ba2
commit
36538725f4
@ -6,4 +6,47 @@
|
|||||||
|
|
||||||
## Envio de Mails
|
## 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](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")
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user