Send automated emails with Node.js! (with Nodemailer)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome back to another video um today we'll be talking about how to send emails um automation emails in node.js with specifically nodemailer um so mailer is a package uh you can find that in um npm so as you can see nodemail is actually uh pretty popular with over a million downloads each week and then so uh here they don't really tell you much about how you use node mailer so i'll walk you through how to use node mailers today so some things you need before we start coding is you need a email account to send emails to someone else and uh that's it well you also need to have node.js installed but you can install that but one thing i want to i want you to look at here is this thing if the email you're trying to use to send emails is gmail if you're using gmail then what that means is it will either work or it won't work right because gmail has a really good bot validation system so if you're trying to send automation uh automation emails it might not it might get the deck it might get detected in gmail and you won't be able to authenticate um so if gmail doesn't work for you then don't use it uh but if gmail doesn't work it's almost guaranteed that outlook well so that's what i'm gonna use today i'm gonna use outlook so i have um this new email that i just created it's called nodemailer and then this is the email name i had to get a unique email name so that's what i did and then i have this other email this the res the receiver can be in gmail that's totally fine but this is the receiver and it's going to be a gmail account and we're going to be sending a an email into this uh gmail account so let's get started all right first things first hopefully you have some kind of structure that that's in your node.js app already i decided to use my first node app from a couple of a couple while ago so i don't even know what i did here but i have but that but you just need a node.js app so you have this app and then you can see this is an app.js from way before basically um i'm just going to be creating another javascript file into this app because i already have the structure set up um so first things first of course you have to install node mailer right so it's just npm install node mailer and then save so we'll wait for that to install okay so uh this message basically if you see this message that means you installed the correct node mailer if you don't see this message that means you either installed something wrong or something else happened but you can see that this is installed right okay so of course what we need to do is we need to um require node mailer right so a required nodemailer no network okay and then what's going to happen with nodemailer is first you need a transporter right transporter is basically where you have the sender information where it authentic where it uses it to authenticate so you need to making transporter i'll just say const transporter order sorry quarter it's equal to node mailer remember it's referring to this node mailer nodemailer.create transport i'm very intuitive right here but you need to create an object inside that is so today i'll be using um outlook which is a hotmail service and right here you need to create your auth your auth is going to contain your user right um see what my great email name is three two node-1231232 three two one all right so if i were you i'd probably create a simpler name but um two three two one at outlook.com all right so now you need the password right i'll just type it in here because this is a test account and i'm deleting it right after this video goes out well i actually forgot something so i'll put my password here it's a very good password that's me so that's the password and then that's it for the transport okay so now we need to move on to our options um so we're gonna now we have to specify what kind of um how we're going to send the email right like what's the subject who is it too um what's the text in it and then who is it from so some very uh intuitive stuff so first we just need to we'll call it um options then let's say it's equal to another object obviously and then so we need a from obviously so from is from this email okay two is going to be to this email which is my other email twitter 16790 at gmail.com and then we need a subject call it sending email with node right.js then i have a text okay and then we'll say let's say that's simple all right so that's going to be our option um pretty basic option in my opinion but you get the idea and now we need to send the mail right um and we're going to use this transporter transporter has a function called send mail and then what we pass in to send mail is our options and then a function a callback function or an error and then some info right so obviously if there's an error we'll print out the error count console a log error um or just return so then i don't have to put an else so now if there isn't an error then we'll just log and fill that response now this is very important if you log info it's going to give you some long json and you just want the response so we'll put um sent then response so that's basically it so now let's run it and then the first time if you're using an outlook account that is new that means you have never sent any messages or received anything you will um get an error now you won't get an error here because i already solved that issue but i'll tell you what error you'll get so you can see that it sent the email so now let's talk about the error the error you'll get is that it's not authenticating so let's go back to our outlook you can see here um actually i recently just verified so hello node mailer to continue sending messages please sign in and validate your outlook account this helps us stop automated programs from sending junk emails so when you try to send an automated message this is what it's gonna um it's gonna send you so you'll fail your first authentication because you haven't verified your account but after you verified your account then you're good to go so basically um follow its steps um use the link follow its steps they'll ask for your phone number sorry well it'll ask you to send a text message to your phone number and then you'll use the code that is sent to you to um to uh verify the account but we sent the email right here right and sometimes um if you're sending to gmail it might go to spam depending on what your content is now if your content's just this it probably will get automated into spam for gmail but if your content's not like this then i probably won't but hopefully it didn't get into gmail as you can see um gmail didn't actually put it into spam but right here here it is we have our email from node one two three one two three two one three two one outlook.com and that's the message we got right here so um if you wanna see it again uh we just run it again and we'll be getting another email pretty soon uh oh all right there we go the email sent so that's the new one right here and this is how you send emails with node.js if you want to see more tutorials make sure to subscribe to my channel um i have tons more tutorials there if you just want to learn some algorithms then you can also check out my playlists and i hope you enjoyed this video make sure to give it a like and subscribe thanks
Info
Channel: Random Coder
Views: 77,120
Rating: undefined out of 5
Keywords: Send emails with Node.js tutorial, Node.js with nodemailer, npm nodemailer, npm nodemailer tutorial, Nodemailer tutorial, nodemailer walkthrough, nodejs nodemailer, nodemailer node js, nodemailer, Send emails with nodemailer, send emails from nodemailer, Send emails with Node.js, Send email nodejs express, nodemailer tutorial smtp, Send email nodejs smtp, send email nodejs gmail, node.js contact form, Nodemailer tutorial gmail, nodemailer gmail, Send Automated Emails
Id: CrdMFZIYoEY
Channel Id: undefined
Length: 10min 41sec (641 seconds)
Published: Sun Aug 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.