‫So, let's now use the Sendgrid service
‫in order to send real emails to real email inboxes.
‫Rather than to our development inbox at Mailtrap.
‫And so, let's open up a new tab here
‫and search for Sendgrid and then it is here,
‫SendGrid.com
‫All right, so we can try it for free.
‫It will then have some limits
‫but you can still create a free account
‫from which you can send like, one hundred emails per day.
‫All right, so go ahead and create your account here
‫and once you're ready come back to this video.
‫Okay, and after creating your account
‫you should see your dashboard
‫that should look something like this, all right?
‫So you see there's a ton of stuff here on the left side
‫you can choose like templates, you can see all kinds
‫of statistics about the emails that you're sending.
‫And really, there is a ton of settings
‫that you can also set here, okay?
‫But for now, what we are interested in,
‫is in the Set up Guide.
‫Okay?
‫So here in the top left corner of your dashboard
‫you should have this menu here
‫where we then want to click the Set up Guide.
‫Now if the page at the time you're watching this video
‫looks somewhat different,
‫then you might also find the Set up Guide link
‫somewhere down here.
‫And in this case here on the sight side.
‫So let's open that up and now what we want to do is here
‫to integrate using our Web API or SMTP relay, all right?
‫And you could also easily integrate Sendgrid
‫into Wordpress or Drupal or something like that.
‫But of course, that's not what we want.
‫So here we want the first option
‫and then we want the SMTP Relay.
‫Because that is the one that we need
‫if we want to use node mailer
‫and create a transport with that.
‫And so that's exactly what we're doing
‫and so we choose this one.
‫On the other hand, we could also use
‫the simple to use Sendgrid API
‫and so then we would choose this way.
‫But again, with node mailer we need to choose
‫this option here.
‫And then from here it's very easy.
‫So here we just need to create an API key with some name.
‫And so that name is not really relevant at all,
‫so let's just call it "natours".
‫Create Key.
‫And so now to configure or transport a node mailer
‫all we need is actually this user name and this password.
‫So let's add these two to our config file
‫so I'm copying the password and the user name is "apikey."
‫So, config.env
‫and then everything that's related to emails,
‫let's put that here.
‫So SENDGRID
‫USERNAME
‫is apikey.
‫And Sendgrid PASSWORD
‫is this one.
‫And once more I really ask you
‫to create your own account and your own API key
‫and password instead of using mine, okay?
‫Because if many people do that,
‫it will quickly stop working for everyone, all right?
‫So please create your own account
‫and generate your own password, okay?
‫So there is actually enough for us to create or transport.
‫And so let's do that here,
‫so node mailer.createTransport.
‫And now, remember how I told you when we first created
‫this email handler a couple of seconds ago.
‫That there are some services that are already predefined.
‫And Sendgrid is actually one of them.
‫So we can specify service and then set it to Sendgrid.
‫All right?
‫And we actually did this before for Gmail
‫and with that all we needed to then pass in
‫was the user name and a password.
‫And so here is going to be exactly the same.
‫And that's the reason why we actually don't even need
‫to specify the Server and the Port, okay?
‫Because node mailer already knows this data
‫because is specifying this Sendgrid service.
‫So now, we just need to specify the authentication
‫and the user is at process.env.SENDGRID
‫USERNAME.
‫And now let's just duplicate this here
‫and here, pass.
‫Okay, and that's actually it.
‫And now to test this, let's create a new user
‫with a real email address.
‫So we go to Postman and let's close all of these here.
‫All right,
‫and so I will create "Jonas."
‫And now as the email address I will create one of these
‫disposable emails which is basically an email address
‫and an inbox for which we don't even have to sign up.
‫So, we're going to use the Mailsac service.
‫So that goes like that,
‫and so here we can now really put anything.
‫So let's just put "Jonas"
‫and then everyone can access this, all right?
‫So I will now register with this email address
‫and so the welcome email should then end up in this inbox.
‫And you of course, when you're testing this on your own
‫can of course use your own email address for this, okay?
‫So go ahead, create a user basically for yourself
‫with your own email address, and then hit "Send."
‫And so now our email should be sent using SendGrid.
‫And now that might take a little bit of time
‫but let's reload here, maybe it's already there.
‫And actually it's not.
‫So let's take a look at here our dashboard.
‫And from my experience,
‫this actually doesn't work right away.
‫So for example this "EMAILS TODAY" number here
‫always takes some time to actually update.
‫And also the first emails that you send,
‫they not always actually show up where they should.
‫So this behavior that we're seeing here is kind of normal.
‫But let's try this again, so we still got no email here.
‫But actually the reason for that is
‫that remember that this transport is only going to work
‫in production and so actually we need
‫to run our application in production.
‫Which right now we are not doing.
‫So let's now do that,
‫npm run start production,
‫and so let's now actually try that again.
‫So first I'm going to delete the user that we just created.
‫So it's this one here,
‫and actually let me delete all of these
‫that we don't really need,
‫so all these test users.
‫All right, and so now let's try this again
‫with this email address.
‫And that is still successful and now let's take again
‫a look at our email inbox.
‫We look that, and now we get one message!
‫So, when we open that, then here it is.
‫Now for some reason, this application
‫is doing something weird with this button here.
‫So it seems like they are applying
‫their own styles here to this email.
‫But nevermind, what matters here
‫is that it did actually worked.
‫And so now, we send our very first email
‫using Sendgrid to a real inbox.
‫Now let's just see if it actually shows up here as well.
‫But as I said, sometimes that takes sometime to show up.
‫So as I mentioned before, it still shows zero emails here
‫while in fact, we already sent and received one email.
‫Okay.
‫So great, so with this you can now send
‫up to one hundred free emails, I believe.
‫It says something here, yeah.
‫So with the trial, that you just started
‫I think it's even more,
‫it's like thousands of emails per day.
‫But the after some time, you get downgraded
‫to just one hundred.
‫So if you have a real app and a real company,
‫of course you'll have to pay for this one (mumble).
‫But then at that point, that's also no problem hopefully.
‫Anyway, this now wraps up our part about sending emails.
‫And in the rest of this (mumble), we're now gonna be talking
‫about accepting payments with credit cards
‫and creating bookings in our system.
‫So that is really really exciting and so,
‫I hope to see you there soon.