Nodemailer | Send Email using Nodejs and Nodemailer from Gmail | Gmail

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 mail using node js for that you don't have to be an expert in nodejs if you have some basic understanding about nodejs you are good to go ok guys here you can see I have opened my terminal let me create directory for that say mkdir emailsender nothing more fancy here you can see i have created that folder let me get it into the folder let me say change directory clear this all ok guys you are very familiar with initiating a node project you have to say npm init nothing more than that just hit enter enter enter if you want to change entry point as server.js you can do otherwise leave it as it is i am leaving as it is hit enter enter ok just yes here you can see getting our package.json after initatiing the node project let me install a package which is going to help us to send the mail which is nodemailer here you can see this is the package which we are going to use to send mail here i am not going to use express or any frameworks just this package alone does the all work for us say npm i nodemailer and the code is pretty forward just we are going to use only to methods one sendmail and another one is createTransport hope things will get under stand get into vscode for entering vs code you have to say code and a space and a period hit enter it will take to vs code here you can see guys we opened our vs code here you can see we have our node modules and package-lock.json and package.json in the package.json we should have nodemailer that's the only package we installed nothing more than that let's create our index.js file for that say touch index.js or otherwise you can go here and create file it doesn't matter we created our index.js file get into the file import the nodemailer for that you have to say const name it as nodemailer nothing more fancy let's say require nodmailer ok successfully imported the nodemailer and we have to create a variable which is transport let me do that first and i will explain you later let's say let mailTransporter here we have to use method called createTransport which is offered from nodemailer and this method is responsible for sending our mail this guy alone does all the work for us it does take a object which is service and authentication and we are going to use gmail as our service say gmail ok after that we have specify our authentication let's say auth here you can see guys this are the properties of createTransport method and it does take username and password user is nothing but the sender's mail address here i have created a dummy mail address for teaching purpose i will share you the password and don't worry i will delete the account after uploading this video if was actually this mail id i created for you guys this is the test demo and the mail id is demo28052002@gmail.com and here you specify your password which is more important don't specify wrong password otherwise it doesn't work and the password was sahul@123 that's it we created out mail transporter which is responsible for sending mail let's specify our details like from mail address and to mail address after that subject and text for that let me create an object let's say details it is a plain js object specify from address and in to address i am going specify my official mail address which is sahulhameed2815@gamil.com we have to specify subject and text let's specify subject as testing our nodemailer and in text say testing our first sender you say whatever you wish it doesn't matter just i am showing how to use this nodemailer and mailTransporter now from mailtransporter there is method caller send mail which is going to send mail and it takes the details and it takes a call back if you very familar with express you guys can do easily if it has any just say console.log it has an error let's specify the error here otherwise in the else block you can say console.log email has sent that's this is the code let's run our application it doesnot give any error for that open terminal say node index.js hit enter oh it says TCP connection error let me get to the createTransport i have misspelled the gmail here which is the actual error say gmail you have write the spelling correctly otherwise it will give an error like this ok let me re run this once again it gives an another one error this was the error which expected earlier but i got that spell mistake error ok for this you have to get into your gmail account and you have to enable less secure apps let me get in to gmail account click on that icon here you will get the option of manage gmail account and in the security section get down you will find less secure apps google automatically turns it off consider if you are entering in a site which does not have modern day security easily hackers can attack let me turn on this if you didn't turn on this it does not work don't worry it does not make you that less security after turning on the less secure apps get back into the vs code and re run this app and this time it will work here you can see guys email has sent get into the gmail account and lets's verify let me re run this see guys we get our testing our first sender two times i run it two times so we are getting two times let me get back to vs code and change text content as testing out it check once again this time it should give any error and we should get testing out it check once again in our mail say node index.js here you will see email has sent let me get it into mail address re run it and say reload here you can see testing out it check once again that's it the code is pretty simple and straight forward you have to use createtransport method from the nodemailer and send mail method nothing more than that and don't forget to turn the less secure apps and please guys don't try to copy my mail id and password because i will delete this after uploading my video that's it guys i hope you have learnt something Thank you tata see you Do Like Share and Subscribe
Info
Channel: sahul
Views: 48,494
Rating: undefined out of 5
Keywords: mailusingnodejs, nodemailer, gmail
Id: JgcDZl8eXTg
Channel Id: undefined
Length: 11min 39sec (699 seconds)
Published: Tue Jan 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.