How to send mails with Gmail using nodemailer after less secure app is disabled by Google?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign so here we have an application that is running on Port 3000 so if you want to send an email with uh using Gmail using node mailer then we have to install a package called node metaphors installing the package node mailer okay so then uh we have to require the note Miller then we'll create one API endpoint this is going to be a get request to send emails which is going to take three parameters requests response and next next okay so now to send an email let us create a transporter [Music] dot create transport so it takes parameter service so we are using service of Gmail then it is going to take a second parameter of art which is going to be a user so here uh you should put your it's email address that is mine is sure at the rate gmail.com and the second parameter is going to be the password of your Gmail so I have put the password of my Gmail and the environment file so I'm just going to grab that one from the environment file foreign the transporter then we will create one option so this option will contain from from parameter that is going to be the email and that we are sending it from so it is going to be the same as the one above then do so just going to put my other email then subject it is going to be just test and text is next okay so after creating the transporter and the option we are going to send the email now so that is going to be transporter Dot send mail the first parameter it is going to take is the option so this is going to be the option then the second parameter we're going to create a function which will take and the error and the response or info [Music] so if we got an error error while transporting the email or while sending the email it is going to record here so for we are just going to console log the error here and and if it is sent successfully then we will just cast this in the else statement uh that is going to be console log mail send then we're going to guess the info here so before sending the email uh so Google has given us some options like we have to enable the security of our email to the secure app but for sometimes this uh this feature has been removed by Google so we will not be able to send the email uh using the less secure app so let us check here so our application is running on localhost 3000 then send email sorry this is not running okay let me run this one node index.js slash it's okay uh so if we run this endpoint so the problem was we forgot to restart the server so restarting the server now uh so if we send the same request again then here we can see uh that we are receiving an error that is invalid login uh username and password not accepted so this is because uh Google has removed the less secure app option a secure app option uh so yeah uh so we need to take on the next approach so let me first and the connection here so we have to take on the next approach uh so after Google disabled the less secure app we need to create the password for the application so first of all what you need to do is go on to the uh manage your Google account Account button and click on it then go to the security tab here you'll see do affiliate verifications [Music] so first of all what you need to do is to enable your 2fa verification in your account so uh let us verify our so after enabling the two fa or posted verification for your Gmail account you will see one additional option that is app passwords just below the two-step verification so here uh we will need to add our uh at our applications uh add our application information here so that we can send it a password for our application uh to use it to send the email so first of all we will select the mail then on the select device we will add a custom name so I'm giving the name like send emails so when I click on the generate button so if you click on generate it will send it a new passport which is visible for one time only so you need to copy that password and place it in your application so I have already placed the password in my environment file so you can paste it here or you can create your own environment file and paste it there so this pass is going to be your Gmail application password now so let us run our application and let's run the endpoints and emails so okay uh so we have received the success email so yeah uh so this works now uh so if I check in my Gmail I should receive this email so yeah uh this is how we can send the email using node mailer and Gmail uh when uh Google disables the less secure app thank you
Info
Channel: Explained By Example
Views: 3,870
Rating: undefined out of 5
Keywords: nodemailer, less secure app, less secure app disabled, npm nodemailer, how do i send an email from gmail nodemailer ?, gmail allow less secure apps, allow less secure apps gmail setting, allow less secure apps gmail not showing, turn off less secure apps, send email in nodejs, send email nodemailer, gmail nodemailer, less secure apps, nodemailer gmail, less secure app access not showing, nodemailer send email, send email nodejs gmail, nodemailer tutorial, explained by example
Id: l--0JyIS5Ts
Channel Id: undefined
Length: 9min 17sec (557 seconds)
Published: Mon Dec 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.