Send email with MailGun + Nodemailer - Nodejs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys welcome to another video and today I'm gonna walk you guys through how you can use Mill gun and node mailer it together to send an email well without any further ado let's get our hands dirty so for this one I'm inside a folder called same email very basic I'm gonna go here and initialize a packet that JSON using NPM init - why and this is technically gonna go ahead and create a packet that JSON for me so once I have that packet that Jason create it I need a total of two packages the first package that I need it is something called node mailer in the second package that I made it is something called node male or male gun - transport and once I do that I make sure that I save that one as a dependency all right so once I have these two packages created I can now go ahead and create a file call server that J yes answer for that yes it is going to be the file that contain every single node Miller configuration so first thing I'd like to do here is go ahead and bring node mailer itself now after I bring the mail and I'd like to bring the node mail or email country sport and there you go I bring these two packages right there so once I import these two packages that I need in order to configure mailgun with node miller i need a total of 4 step step number one I need to go here and define the authentication for node mailgun and this one here gonna contain an oath and inside this off is gonna contain API underscore key and here is going to be containing the key from my milk a cow remember we do not have the milk an account we're gonna go ahead and create it but before that that's actually our extra key in the second thing that we're going to need from the milk on account we're gonna need something called domain and we're gonna walk you guys through how to get both of them but let's leave them empty for now in ladies and gentlemen we are done with step number one step number two in order to work with node mailer we need what they call a transporter in transporter is typically what going to allow you to connect with whatever place you'd like to connect in this gate I'd like to connect with Mel gun while the transporter is going to be what connect node with mailgun so in order to do it I'm gonna go ahead and create this Bible called male transporter and I'm gonna use node mailer in this case I'm using this node mailer here node mailer and I'm going to use something called create transport once I use that I need to call the made note mailer gun which is where I want to connect to once I use it like this as a function I need to pass the node mailer configuration here which is this 4 so I'll take that off and pass this one has an extra copper parameter and ladies at the main we are now done with step number two step number 3 is where we're going to define our mail options just as what do you want the user to see and in this one have something called from in this one it's just saying excited and this one is just a simple email coming from node Miller as a way to tell the user that this is what this email is coming from second effect you have the two property here and to easy it is important it is because where we want to send that email well in this case we want to send this email to this particular email address third I'd like to use the property subject just to kind of give it a subject for the user to instantly see the subject that is coming in last but not least I also would like to have a text in text it's gonna be the content of the body that's gonna contain inside our our email and once again guys we use our farm to use object in text and then ladies and gentlemen we are done with step number three and now we only have one step remaining in step number four all we need to do now is grab our transporter which is this one we're gonna grab our transporter in step one day three and we're gonna use a function called send email and the sent email is going to contain the mail option inside step number three and we're gonna copy this mail option incentive here and after we've done that we're now gonna give it a callback that's gonna take two parameter and here we're gonna check and see if there is an error we're gonna console.log that error and else if there's not an error we're going to say message st. now recording codebase we are done let's review before we go and do any mail gun configuration step number one we go and set up our mail gun come step number two we use our transporter we configure it with an old male gun just to make sure that this is configured in step number three is we configure our male option step number four we're ready to send that email now we go in the code base if you guys remember on step number one we need those information from MILCON in order for us to be able to send this email remember those information are coming from Milkin but the question is how can we get access to these two value well in order to get access to these two value we need to go here under mailgun command once you go to this website it should take you to this main page but the bottom line is if you do not have an account you need to sign up to have an account and what mailgun allow you to do is allow you to send a total of 10,000 email for free every single month if you do not have an account go ahead and click the sign up button I don't wet it do you have an account I'm gonna go ahead here and log in with my account once I log in into my account I need to go over where every icy domain this is what I'm gonna be actually getting this value for domain so once I go to domain here by default millions should give you your domain for testing purposes however if you'd like to move to a production-ready state you're gonna need to have to upgrade in order for you to create a domain for production but for testing purposes this domain should be the only thing that I need in order for me to be able to work with this and I copy this domain value and add it here and there we go this is where I was able to successfully get that value but the question is where can I get the API key well in order to get the API key I need to go over wherever you have your email and go over the account setting and once you are inside the account setting wherever you see the security tab and if you go over the security wherever it said primary private API key this is your API key well for mine I'm gonna go ahead to use that API key here and once I do that and I paste my API key in here now for security for the security reason do not use the same API key that I have after this video I'm gonna go ahead and refresh it to get a new API key so that you should not use my semi Bianchi otherwise he would not be working for you in ladies gentlemen these are the two information that I was successfully able to get but before we go ahead and run our code there's one last thing we need to do and the last thing it is very very important in order to get milk on working in order to do that last thing I need to go wherever you have step number three and under wherever you're sending that email to by default mailgun for security reason doesn't allow you to spam any user or whenever you are into testing phase well what that mean is if you testing your application note 1 doesn't allow you to send any email to anyone in order to go ahead and let node 1 know hey this is my personal email I'd like to use this one for testing purposes you need to copy that email and go back to mail gun whenever you own MILCON you need to go again to account setting and over account setting we're gonna go over wherever you have authorized recipient and what that mean is you can configure the email that you'd like to receive the email on just away from the mail gun to be able to believe that this is your email and then you need to verify to be able to receive email for testing purposes so that you're not spamming any order user that are not ready to test your application however whenever you upgrade deploy this one to production you would never need to do that it will be able to send email to anyone that add their email into your application so once you also successfully invite that recipient it should send you an email and once you get that email click on it and go here type a query to go ahead and agree to be ready to test receive an email for Milka and click yes and ladies and gentlemen that should successfully verify you and if you go back to work to milk on refresh it you should be able to see this the state change to verify now however this is very important if you do not see this for the email that you're sending email to you make sure you do because otherwise you would not be able to send email using the sandbox version ok this is important all right so once this is out of the way and go back now to my application and all I need to do now is run my note server app kitchen and there you go ladies that way my email was successfully sent and now if I go back to my email and go here I should be able to see my email is being sent from mailgun and there you go I'm ready to go if you go back to mail gone they give your dashboard and the cool thing about Milken is it is telling you how many email you were able to process and how many were able to successfully deliver and how many were able to drop and how many were able to surprise so the bottom line is you got this dashboard in the last 30 days that you can feel free to have an idea of how many emails that your application is actually sending to users and so on and ready to go and ladies gentlemen believe it or not that is the end of the video [Music] you
Info
Channel: Esterling Accime
Views: 8,776
Rating: 4.9576721 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 sendgrid, nodemailer gmail, mailgun tutorial nodejs, mailgun, mailgun send email, mailgun receive email, mailgun setup, mailgun tutorial, send email nodejs express, send email nodejs gmail, send html email nodejs
Id: i62jmLC15qQ
Channel Id: undefined
Length: 9min 46sec (586 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.