🛑 Send email using Django | How To Send Email With Django | 2024

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello makers in this video we will see how we can send email using django web framework without facing any error so consider subscribing to join makers group now let us get into the video without wasting time if you are here at list you have the basic knowledge of django so i do not want to waste your time by building the project from scratch that's why i have already built a django project which says send email the project has one app whose name is my app it also have a template folder which contain html page to be rendered in view.py let me run the server and show you what i did so far as you can see the project is rendering out the index.html page and i doesn't do anything else this page is not integrated to a database or it couldn't send email to so if you press send you will not get any result now go to setting.py file and you need to set email host equals to smtp.gov email host user equals to receiver email address email host password equals to your app password it is not your email address original password email port equals to 587 email use tls is set to true email underscore backend equals to django.core.mail.backends.smtp.emailbackend replace email host user with the receiver's email address and to generate app password navigate to myaccount.google.com go to security two-step verification should be turned on you can see the video in the description to turn on two-step verification press app password below two-step verification and create an app with your choice of name then you need to press generate you will get auto-generated password so you need to replace email host password with the auto-generated password now let us go to views.py and edit our code in order to send email via django you also need to indent the code appropriately first we have to import two libraries those are from django.cor.mail import send mail from django.conference import settings after importing the library we need to define a function which used to send email and render out the html page now we have to write the code to send email and to return the html page inside the function if request.method equals to equals to post we need to read message emails of receiver and name or title of the email on different local variables as follow variable message equals to request dot post message variable email equals to request dot post email variable name equals to request dot post name now to send the email we need to call send mail function which takes five different arguments those are number one title of the email which we get from the name field number two message of the email which we get from the message field number three email address of sender this is the email which is configured in setting dot py file unless you configured in setting dot py file you cannot use any gmail account as sender so email of cinder described as settings.email host user number four receiver email can be single or multiple or you can fetch it from database you can hard code it or else you can get it from the from like we did in this video it should also be tuple and number five fail silently equals to false consecutively finally we need to return index html now if we fill the form field and press in we will be redirected to the same page that is because we set the url to be redirected to index or home page but if we navigate to our sender email we will find the email in sent email if we navigate to receiver email we will find the email in inbox the title of the email says contact us it is because we didn't pass name to send mail until now now if we replace contact us with name and if we submit the form after filling the form filled we get our email with appropriate format as you can see the title contact form has changed to asking for collaboration and the email is delivered to the receiver email address as intended now we are left off one thing that is you need to subscribe and like the video [Music]
Info
Channel: Makers Group
Views: 35,433
Rating: undefined out of 5
Keywords: django send email gmail, django email, django, django send_mail, django send mail, sending email with django, how to send email with django, sending email python, sending emails with python, django send email, django email form, django sending email, django contact form, python, django sendmail tutorial, learn django, python django, Djangomailsending, gmailsendingusingdjango, emailsendingusingdjango, error fixed, 535 Username and Password not accepted, contact us, django tutorial
Id: iGPPhzhXBFg
Channel Id: undefined
Length: 5min 18sec (318 seconds)
Published: Wed Aug 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.