How to send email on form submission using django forms? -


prior sending mails on actual website, i'm running small test django local smtp server: have congifure these settings in settings.py. put it?

email_backend = 'django.core.mail.backends.smtp.emailbackend' email_host = 'localhost' email_port = '1025' email_use_tls = true 

then how proceed? please help.

you need put these in settings.py file. can put below settings anywhere in settings.py file.

settings.py

...  email_host = 'smtp.gmail.com'  # since using gmail account email_port = 587  # gmail smtp port tls email_use_tls = true     ... 

local_settings.py

email_host_user = 'your_username@gmail.com' email_host_password = 'your_gmail_password' 

then send email, can use django's send_email().

from django.core.mail import send_mail  send_mail('my subject', 'my message', 'from@example.com',     ['to@example.com'], fail_silently=false) 

mail sent using smtp host , port specified in email_host , email_port settings in settings.py file. email_host_user , email_host_password settings, if set, used authenticate smtp server, , email_use_tls settings control whether secure connection used.

signature of send_email():

send_mail(subject, message, from_email, recipient_list, fail_silently=false, auth_user=none, auth_password=none, connection=none, html_message=none)

note: can put gmail account information in local_settings.py , add local_settings git-ignore. include local_settings in settings.py. way able see local_settings.


Comments