Send email with Nodemailer using gmail account - Nodejs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys welcome to another video and today we're gonna walk you guys through how you can use your personal gmail account to send email in nodejs and beside that we also gonna walk with you how you can see see someone or even BBC folks inside nodejs just a quick warning before we start the session if you do have an two-factor authentication activate it into your account this video will definitely not work for you it's gonna require to eat if we temporarily disable it or you're gonna have to use a different gmail account that you do not need just for testing purposes without any further ado let's actually go ahead and get our hands dirty first thing first navigate to folder wherever you have it inside this one I have a folder called send email in this one I'm gonna initialize a packet that JSON in this command is only going to go ahead and create a packet that JSON for me and as you guys can see down here I now have my packet that JSON we're ready to go but once you have the packet that JSON created next thing I'd like to do is go ahead and install a package called node mailer and I'm gonna use the - capital S to save this one as a dependency once this one is done saving as a dependency I'm gonna go now and create a file called server that j/s and this is where we're gonna go ahead and create everything that we need to send that email in there you go guys my server that Chase is now created I can go inside of it and start doing a couple thing first thing I'd like to do is go here and we quire the node mailer package that I installed there you go once I have that install there's a couple step that I need step number one is in order to send any email using node mailer you need what they call a transporter and a transporter is what going to connect you to whichever host domain that using or either services that you'd like to connect you so the bottom line is that transporter is what going to be making that connection for you so in order to do that I'm gonna go here and create and store that transporter into a variable called transporter and in order to create that transporter we're gonna use the node module here and do that create transport so once you do that this transport itself takes an object and we think that object or things that she puts such as the host configuration or anything related to things that you'd like to connect you in this one I'd like to connect to Gmail so I do use service and make it equal to Gmail this is a way saying that we want to connect to Gmail once we have that we pass it the OAuth which gonna need to pass the email and password and to pass the email we pass it over something called user and then to pass the password we pass it over something called pass and let's determine these two key are going to require you to pass your email and password so once I have the transporter created next thing that I'd like to do is here is create my mail option such as what are the things that I'd like to send to my mail in order for me to do that it's just going to be an object that's going to contain everything that I need to send to that user but first I'd like to tell the user where this email is coming from and for this one I'd like to send this email using this account that I have called tap numbers Gmail that email and second I'd like to use the two to tell it where do I want to send that email for this one I have an email called Delta Mavericks and this is where I would like to send my email to third I'd like to mention a subject and this is gonna be what the users see as the headline of the email and for this one I can leave it simple kind of like testing and testing something very very dummy and lastly but not least I can also send a text that's going to be containing inside whenever the user opened this email and for this one I can just say it works something like that very busy once again ladies and gentlemen that was step two now step number three is the last part that you need to do in order to be able to send that email in order for you to do that what you're going to need to do is grab wherever you have the transporter on step number one which was that variable called transporter and I'm gonna use a function only constant email now this function itself takes two parameter the first one is the mail option that you had on step number two so we're gonna go here and pass it that mail option in the second parameter that it takes it has to be a callback so I'll define my callback here in this callback take a total of two parameter which means in case there is an error what do we want to do if there is an if for any reason that we were not able to successfully send our email what do we want to happen in this case I'm just gonna go now in console.log error occurs and else in case after that we have successfully sent the email what do we want to do I'm just gonna go now and just display the message call email sent and ladies and gentlemen believe it or not the recording codebase we are done the only thing that we need to do is adding our password now I'm gonna do an extra step here in the extra step it's just gonna go to make sure that my password and I'm gonna be adding is actually going to be something that is not visible to the public because if I add my email right here and after I add my email and I come here and kind of like enter my password this password is going to be visible to the entire public so I do not want this I want to find a way to configure this one so that it is not visible to the entire public for that one I'm gonna use a package called don't envy and I'm gonna save this one as a dependency and what its gonna allow me to do now is I can go on the top of my file and I can do require don't envy once I do that I can use configure and this is how I technically configure dote envy to load what they call environment variable once again this might be sounds confusing but in order to work with Doulton v-- we need a phone call that envy that envy gonna contain where you add your password and beside that we also need what they call that get ignore file once we create our giving though we need to go inside the get ignore and make sure that we are now ignoring that that E&V file which means this will never get pushed to any way that we send in it this might again sounds confusing but if you guys don't want to go with the extra step you can feel free to just enter your email and password here so we are just gonna go ahead and configure the 10v and once I created this file called that env I can add my password here and then I can also have my email here inside the dot env to your value for example this one is going to be your email here and this one is going to be your password so once you have successfully add your password an email here alright so in order to use those key inside here I need to come here any choice time accordingly so I'll do process not envy and this one is gonna equal to my email that I said inside the VNV file and this one is gonna equal to my password once again guys you do not need this if you just want to enter the email and password right here but for security reason in case you do not want to expose your key publicly then you definitely need to kind of go over it at that entry file and configure it and make it this way so just to quickly review we got our first step which is the transport we got second step which is our meal option and third step which is where we saying we use the transport to send the actual email now if I try to run this application now to make sure that if I can see if I see an email and error occurs and if I go here and just display the error and there you go guys this error is saying user and password not accepted well what we Lee is happening is by default Gmail security is extremely intense Gmail does not accept that you sent the password in plain text to them okay so this is very very important this is an extra step that you need to do to make sure that you can at least test making sure that this is working to test your application so in order to disable that Gmail feature I need to go to this link call my account slash Google comm less secure and once I go to this website I need to make sure that I'm selecting the account I would like to use for this one I'm using the tab number account and once I am on the top now breakout I need to click this button to turn into green and now once it is green I can go back and try to run my application now and it should be working as expected and there you go guys I was successfully able to send the email and now if I go back to my email account and there you go ladies and gentlemen I was successfully able to see the email that is coming in there your IT testing and here's much this object and I can feel free to go ahead and adjust it accordingly and I can feel free to test this accordingly just to make sure that is is it really working and again out on my note application an email sent and if I go back to my server again and there you go this new message is now coming and there is my message as well ready to go alright so nada have successfully able to send an email you might be asking alright so how can I send an email to at least multiple people well if I'd like to send an email to multiple people wherever I have step number two and go over whatever after two and here I can add a comma and add the second email that like to send this email to you for example I'd like to send the same email to this person and also this person and what this gonna do is it's gonna go ahead and successfully send that email to both of the person the other thing that you also might be wondering okay sterling what how can i CC somebody into this email well in order to CC somebody into this email I can go ahead and add the ccc here and technically at the person email that I'd like to CCC into here in there you go ladies and gentlemen we were able to attach that CCC here and if I run my application again an email was successfully sent and if I go back to wherever my email here and go over at that time and there you go ladies gentlemen I was able to send this email to two folks and I was also able to CCC myself into it how cool is this now the other thing you might also be asking how can you be BC some folks well if you would like to beat me see some folks just have the word BBC here and also include the email that you'd like to BBC in there if you I was able to BBC folks to either CCC folks and either send an email to multiple people as once if I run this application again and there you go guys my email was successfully able to be sent and if I go again here I should be able to see my email and including couple folks not now BBC of course you would not show you the folks that are BBC but just keep that in mind behind the same theories of folks that is BBC that can see the emails that you sent now one last thing I'd like to mention here which is very important be mindful whenever you BBC occc's folks this is actually sending an email to that person as well so be mindful which folks that your CCC otherwise they will be able to see that email coming in one last thing I'd like to mention here is the way note mailer work it also worked with a promise if you using the transport that same email where this is also going to return a promise if you do not pass it a callback alright so this might have been confusing but the bottom line is for folks that are advanced just be mindful that this one exists in case you would like to write you know Miller using promises in JavaScript now you might be on it wondering okay sterling great I was able to successfully send an email but how can I at least send a picture with this email well ladies gentlemen you're going to see how we can send an image with our email using node mailer and see you guys in the next video [Music]
Info
Channel: Esterling Accime
Views: 65,636
Rating: 4.9444094 out of 5
Keywords: nodemailer, nodejs nodemailer, nodemailer tutorial, node.js contact form, contact form nodemailer, contact form email nodejs, contact us nodejs, contact form with node.js, nodemailer email templates, nodemailer tutorial 2018, nodemailer reactjs, nodemailer gmail, mailgun tutorial nodejs, mailgun, mailgun send email, mailgun receive email, mailgun setup, mailgun tutorial, send email nodejs express, send email nodejs smtp, send email nodejs gmail, send html email nodejs, nodejs
Id: Va9UKGs1bwI
Channel Id: undefined
Length: 11min 49sec (709 seconds)
Published: Mon Feb 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.