1๐
โ
I believe in your settings.py
you are going to need to add some email configuration, like this
EMAIL_FROM = 'youremail@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'something@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
Then you could create a view that calls the send_mail
function. Something like this
def send_an_email(request):
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from@example.com', [to@example.com'], fail_silently=False,)
return render(request, '/email_sent.html')
Of course youโll need a url to call this view. So in your urls.py
(I assume you have this already) have something like this
url(r'^send_my_mail/', 'Project_name.views.mail.send_an_email', name='mail')
And then visit the url to see if the email got sent properly.
๐คMatt Cremeens
Source:stackexchange.com