Django sending email using Gmail account | How to send email using Django | Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi folks welcome back to my channel  in this video let's learn how to send   email using django before the attack if you are  new to my channel just click the subscribe button   and turn on the notification okay guys without any  say let me get into the code here you can see guys   i have just created a django project till now i  didn't create any app for that let me see here you   can see guys the main difference between a project  and an app is a project is basically the entire   website but a app is just like this sub module  like a sub feature you can create any number of n   number of app with in a single project okay guys  without any say just let me say this once again   python manage dot py startup mail sender hit  enter you will see here mail center here you   can see guys we successfully created our app okay  guys let's first get into the settings dot py okay   let's first specify our apps in the installed  abstraction for that you have to say mail sender   dot apps dot mail sender config okay say a comma over there here this  mail center config name must be same as this   this apps dot py otherwise it doesn't work guys  so that's why be careful while writing this   okay guys we successfully specified our app  in the installed apps okay let's get into the   what is that mail sender  let's get into views dot pi   before creating any further let me create url by  okay let's say get into mail sender and say touch   let's say urls.buy okay guys we successfully  created urls.pi before that let's get   urls.pi which is inside the project my project  let's say url dot by let me remove all this   let me remove all this extra unnecessary  stuff let's import include here   okay guys we have to specify our app path  here otherwise our app doesn't gonna work and   we can't specify our app any other way further  you have to say path let's say mail sender   okay let's see let me see this building correctly  okay guys here i have to include my clud my urls dot pi which is inside the mail center  for that you have to say mail sender dot urls okay okay guys say a comma order   okay let's save this file let's close this  file let's close this file let's come back   views dot pi which is inside the mail sender  let's say get into the email stand door   and in the views dot pi let me say dev index  let's say a request and let's just send rest return http response or better let me create a file guys  why should i go for http response okay guys   let's create a http html file for creating  templates you have to create a folder called   templates inside the our app which  is mail sender not in the project   for that let's say a folder which is template otherwise here you can see guys here  you can go and see no new folder and   and name it as templates and butter i am going  to create a folder in this way using terminal   let me say hit enter here you can see guys  i have created a folder called templates   inside the template folder i have to say create  another folder which i have to name as mail sender   this step is pretty simple guys first of  all get into the project after that get   into the mail sender after that create a folder  called templates after that get into templates   after that create another folder called  the same app name not the project name   here our app name is mail sender  for that let me say mail sender   okay hit enter here you can see guys in the  templates folder we have another one folder called   mail sender okay guys let me get into the mail  sender let me create a html file let me name it as   form dot html okay guys here you can see guys  i have successfully created a html file inside   the mail sender which is inside the templates okay  guys let's say html5 we will get the template here   let me rename as may say send mail nothing  more fancy whatever the name okay guys here   let's create a form of what does  it okay with a method called post   let me undo this action here we don't need this  okay guys let me create three field one is subject another one is okay let's create input field for that subject  let me name it as subject nothing more fancy   just say subject and another one  field which is for message right   okay let's create a text area for this okay let's  say name is gonna be the same which is message   and here let me undo this id here we don't  need this okay guys let's create another one   field which is for email let me say email okay  let me create input field for this let me say   input let me undo the text and say email and we  have to name it as email it keep it simple don't   confuse yourself okay guys here we have to  specify this csr of token for that let's say   open curly braces with percentage  symbol oh what went wrong okay let me create another one whereas the  percentage simple let's say c as or token   okay guys let's get into the  views dot py and just say return render here we have to specify our request and we  have to specify our file which is inside the mail   sender right let's say mail sender slash form  dot html okay guys let's get into our urls.pi   we have to specify our path right for that  let me get into urls.pi which is inside the   my project let me copy this okay let's delete  let's close this file and get into urls.by   which is inside the mail sender okay let's paste  this i think we don't know this let's close this   okay let's delete this let's delete  include here we have to import our   views for that you have to save from  this folder so that we are specifying dot import let's say views okay guys let's keep  it as the home view for the time specifying uh   empty slash over there let's say use dot  index that's it nothing more than this   okay guys let's run our app it's  already running we don't have any issue   let's save this and get back to the browser  and check here we are specifying the   path name as mail sender for that we have to get  into mailcenter right mail center here you can see   guys we successfully we are successfully  getting our form let me uh go to the bar   form.html let's specify a heading over there  this is okay mail center nothing more complex okay just say save it and get back to  this controller here you can see okay   guys let me give you a br over here and  another b or do we need another one br oh control save this what went wrong   guys let me see another one br which is here under  the text area okay let's save this and check here   you can see guys we have to specify our subject  we have to specify whatever the message and we   have to specify the email at last i have to  specify a button how can i forget that okay   let's see a button and a type is gonna be summit  okay let's see send mail send nothing more than   that okay we have to get our button right okay  we got our button let me add a vr over there okay   we got a button okay guys with that said  let's get into the chango which is views.py if request dot method is equal to post right if the  requested method is post what we   have to do we have to do something  right okay guys let's say subject   let me say request dot we have to get it from  the form for that we have to say request dot   post dot get with the name the which input has  the name subject just get that as subject okay   here the input name the name is very important  what are the name you have specified here that's   what we have to say in this particular field  for sub i am getting the subject okay i hope   you understand let's say subject and we have  to say message right for msg just do the same   just copy this and paste this over here i  have to remove the extra is equal to sign   okay let me remove that here i have  to say the message not the subject   okay let's say message and at last email we have  to get the user mail right let me paste this   and remove the subject and say email okay so let's  print out subject message and email whether we are   getting it correctly or not for that let  me say print okay sub comma message comma email okay let's save this before that let  we have to send a response right we   have only specified the response for  get till now we didn't specify any   response for the post method for that  we have to say return http response here you can see guys visual studio could  automatically import the http response   the response is gonna be email  has sent nothing more than that   okay let's control save this and get back to the  browser before that let's check whether we have   any error or not here you can see guys we don't  have any error let's get back to the browser   and say testing let's write something here this is  a test message test mail uh let's specify whatever   the mail it really doesn't matter for now okay  let's see here you can see guys we successfully   get the post response and here you can see  guys here we are getting the subject testing   and the message and the user's mail address here  it means we are not getting any error in the form   or in the views dot py okay guys till now we  didn't specify anything for sending mile just   we are getting we are setting a form and getting  the inputs nothing more than that here we have to   specify some settings in the settings dot py for  sending email for that let's get back into the   emails dot py just say email host if you are too  lazy to do this just get into the stack overflow   stack overflow how to send mail using django just  say stack overflow how to send mail using java   you can see guys just click on the link which  you are getting at the top most just click on it   just go down and you will find out here tick  mark just copy that here you can see guys we are getting the tick mark and just copy this  you don't have to worry about this i will explain   you just copy this guy and paste it over the  settings dot py here you can see guys i have   successfully pasted it here you can see our email  host is gmail.com because we are going to send   a email which is from the gmail okay let's  change this to my official gmail let me say this   2 8 one file on gmail.com which is my which is  my official mail id guys okay let me we have to   change this password i am not going to display  my password here because for security reasons   okay guys so you have to specify the correct box  but otherwise it doesn't gonna work you have to   specify a port number and you have to specify  the tl tls connection you have to say it as true   okay guys make sure whether you  have entered the correct password i   i can't able to display the password  because of the security reasons   okay guys i hope you have specified everything  correct over there if you have done anything   wrong you will get error it really doesn't matter  if you are getting any error just don't forget we   don't get any frustrated just go on stack overflow  there are many members to help you okay now we   have to use a method from django dot core dot  mail not management from mail we have to import   oh let me say import we have to import them method  which is male sin or not male and mean male sin   why it isn't to work let me get into the django  official website you have to say django send mail   okay here we are getting the topmost link click  on the link just say junko.cool.mail that's what   i have specified right okay oh how to say the  method send me not mail said okay guys here   we have to use that matter let's say send mail  here you can see it is asking for a subject here   our subject is sub and it is asking for  the message here our message is message   okay after that it will ask you for the from  mail address which you have specified in the   settings dot pbi your official main address  which you have specified in the email dot   sorry which you have specified in the centric  dot py and specified your password right that   mail id is gonna be our from mail address which  is nothing but my official mail id 2815 gmail.com and here the receipt the two mail address the  recipient list here we have to specify inside the   list which is gonna be the email okay that's it  guys i think we have successfully completed this   let me go to the browser and get back to the  send request sorry get request okay before   that let me use temp mail for displaying you okay  we have to get a mile right here you can see guys   this is the temporary email address you can get  any uh email address for temporary i think it   is valid for 10 minutes here you can see guys we  get a mail address just copy this okay let's say   testing let's say this is a testing mail id from  django app okay we here we have to specify the   mail id which we have copied just say control  v we have to say send it may take few minutes here you can see guys we are getting uh  something a smtp authentication error because   if you even though if you have specified  correct password in your settings dot pba   for the email sparks but if you have done this  two-step verification it it will gonna raise   this error for that you have to get into your  gmail account let me say manage my gmail account and here just get into security you have  to create a separate password for this app   for that let's get into the here you can see  guys i have done my two-step verification for   that i am getting the error even though i  have specified the correct password in the   email host password here i have to create a  new app password let me say a password okay   here you have to specify the correct password  let's corre let me let me see my correct password   unfortunately i can't able to  say show password let's say next okay here let me see mail   here you have to specify your device on  your there is nothing mine let me say other custom name let me give it as  ubuntu okay here it will generate a   password for me here you can see guys i  am getting a password let me copy this   and you have to oh sorry not see  let me copy this ctrl c and say done okay guys if we successfully copy that  password just get back into the settings dot py   and paste it over the email host password if you  have done the two step verification you have to   do this like in this way otherwise it doesn't  work let me paste this okay just say control yes   let's get back to the browser and let me  refresh it once again let's say continue okay what it mean here you can see guys we  are getting email sent that means we are   getting the success response let's get into  the temp mail and check it what has happened   here you can see guys i am getting  a two mil which is uh i have done   previously and which i have done now  let's get into this and check and let me okay what went wrong here you can see guys  we have getting this aim this is your testing   okay let's delete this guy okay guys  let me do this once again for you okay let's see testing for demo testing for something it's a bad  name let's say this is something we have to get   the let me paste that mail id here oh  let me copy that mail id once again let me get into this up let's see we have to get  send mail. we have to get this success response   for the post request here you can see guys  is successfully getting this success response   we have to get into the temp mail and  check our inbox let me refresh this it says your inbox is empty wait a minute  people get okay here you can see guys   testing for something here you can see  just now i said the subject has tested   for something and uh get into that here  you can see this is what we have done there   that's it guys we are successfully sending mail  using django the what actually matter is if you   have done the two-step verification you have to  create a separate a password here you can see guys   i am deleting this in front of your eyes don't  try to copy this otherwise it doesn't gonna work   here i deleted this that is guys just get  into the app passwords and create a select   tab select device generate a random password and  paste it over there simple just four lines of   quotes here you can see we are using a simple  method that's it guys thank you for watching
Info
Channel: sahul
Views: 8,761
Rating: undefined out of 5
Keywords: Djangomailsending, gmailsendingusingdjango, emailsendingusingdjango
Id: Sp78HO7rJMc
Channel Id: undefined
Length: 23min 34sec (1414 seconds)
Published: Sat Jan 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.