Hey there.
Everyone had a share.
And welcome to another video.
The next hour that we are going to work on is Forgot Password.
Now Forgot Root Forgot Password.
Root has to component itself.
You might have seen already in majority of the websites that first you actually go on to the forgot
password page.
There you simply enter your email and say, Hey, I forgot my password.
Now once you click on that, it obviously goes into the database.
Look for the user, whether this user exists or not, and then sends you instruction over the email
itself.
And then you simply click on the button and allows you to ask the change the password or set the password
in that case.
So for this, obviously we are going to need to shoot an email and we already got the node mailer and
shooting the email is really well the easiest thing of all in the entire world.
And this example itself is just more than enough.
Let's go back up here and create a utility for that, because obviously this is a mail function and
maybe a lot of people and a lot of places it might be useful.
So let's go ahead and create a new email and we are going to call this one as simply email helper because
it's going to help us to shoot email.
Did I wrote it correctly?
Yep.
Looks like really short one.
They're very difficult to see.
Come on.
Email.
Helper dogs, of course.
Okay.
Yeah.
Looks good.
So how this is going to work?
We are going to just borrow the code.
Absolutely.
From here, we have already installed the node mailer, so first line is to bring the node mailer.
Let's go ahead and bring the node mailer.
Now we're going to go ahead and export a method.
So let's go ahead and call this one as simply what should we call this one as male helper.
Yeah, that sounds a really nice name.
And obviously this is going to be a simple async method and this one is going to go like this.
And there we go.
Now, once we are done with that, obviously the most important thing to is to export this one.
So we're going to go ahead and say module dot exports and we're going to be exporting this mail helper.
Okay.
So once we are done with this, let's go ahead and work on with that.
Now what we're going to do is further on the road is again copy more stuff.
So we don't need to create any test account and all of that.
We will be directly working on this transporter.
So let's go ahead and first, in fact, let's bring all of this and then we're going to figure out how
to modify it.
So let's go ahead and bring this up.
A lot of information is coming in.
So the first step is let's go ahead and change this one to cost because we won't be changing it.
The transporter?
No, the mailer will create a transport for us.
It requires a host port.
We want to be using secure and things.
So let's go ahead and remove this part and then we need auth, which requires user and password of the
email itself.
I will walk you through that in a second.
So these are all the options that we are going to grab.
And then it says that, hey, I will be sending an info and it will evade the transfer.
Now again, we don't really want to hold this into available because we won't be using it once the email
is sent.
That's aid.
That's all what we want.
So I'm going to go ahead and remove this one and it simply says, Hey, transporter, don't send mail.
And that's it.
Now, I really don't want this integrity of the message up here.
I would like to cut this out and would like to store that into a into a separate object.
So let's go ahead and call this one as simply message.
And that one is going to be just exactly what we copied it here.
Now, it has a lot of options.
There is a from to subject, text and HTML as well.
We're going to assume that this all from two and all of that are coming from the options so somebody
or anybody who is using this will provide us these options.
So there we go.
And feel free to call the data option whatever you like to have this one.
Okay.
So to email is obviously going to come up from this one.
So options, so let's go ahead and work on with that.
So we're going to say option dot email.
So send me the two email.
You can call it to email as well in case that sounds a little bit more sensible to you.
But again, totally under you now the subject we can actually hard code the subject but let's make this
helper a little bit more flexible.
So we're going to say this one as option dot subject and then the text message.
So this one is going to be save as option DOT message.
And inside this one, also what we're going to do is rather inside, instead of wrapping it into a B
tag, we're going to wrap it into a tag because as of our priority need, what we need to do is send
up a link that is clickable.
So we're going to go ahead and wrap this up.
So the entirety of the link is actually clickable and we have to send the ref as well.
So we are not going to send any HTML.
I'm pretty sure later on we can configure that, but right now I'm going to go ahead and just remove
this body part.
We'll work on the copy pasting as of now, but later on we can figure out this one.
So that is it.
That's all what we need.
But there is a little bit more to it.
We still don't have these SMTP details.
What is the host port auth and all of that.
So for this, I will work on to another service.
Let's go ahead and Google on that.
This is really one of the industry standard service mail trap and you'll find see dozens of industries
using it.
This is like the industry de facto of using the thing.
Just like postman is there to test out all the emails.
There is mail travel.
Oh really.
One of the most amazing service that you can work on with that.
So I hope you can see that they works with almost every language.
If you'll check out the company details who is using them, you'll be pleasantly surprised that from
Adobe to Atlassian to pretty much everybody, every big name uses them, whether they mention it or
not, go ahead and create an account.
They are pretty generous with their services.
So there is a free service as well.
Feel free to use as much as you like on the free one.
They have a pretty generous plan, a login into this one.
So I might be having an account.
I guess I have a account from Google.
So yes, I have a Google account on this one and all I got to do is simply work on with this one.
So what I'm going to do is I need to grab all of the details from where I can grab this one.
Let me quickly go ahead and see that.
Yeah, this is my inbox and let's go ahead and see SMTP settings.
So again, these are integrations being sent.
I am interested into the node here.
So Node Mailer is pleasantly mentioned up here.
So these are all the details that I can have so I can definitely go ahead and replace.
If you noticed, this is entirely a code is given to us, not just the details.
So we have got SMTP, host, port user and password.
All of them are there.
Now what we're going to do is for host, port user and password, we are going to go ahead and store
them into our favorite place process E and v, so E and V file and let's go ahead and add the mail details.
So we're going to go ahead and call this one as SMTP, a really short for simple mail transfer protocol.
So we're going to go ahead and let me see what else we are having up here.
In fact, it would not be wrong if I just go ahead and copy this for a minute and paste it up here at
the top so that I can at least right.
That.
So SMTP underscore host then we have got SMTP underscore port and then we're going to have an SMTP user
and then we are going to have an SMTP pass.
There we go.
So all the details are up here.
All I need to do is put an equal sign and then put up all the details up here so I can go ahead and
put like this.
And there we go.
Okay, let's go ahead and fill this up.
So this needs to go.
Cut this out, paste that up here.
Oops.
My bad.
So cut this out and paste it up here.
This is the port so we can go ahead and cut this out and paste it up here.
This is the user again, in case you are signing up for some other services like eight of Lewis send
in blue or whatever favorite is yours so you can go ahead and just change these details.
And Node Mailer will absolutely work fine in those cases as well.
Okay.
So now there is no need of this one.
There we go.
So now all of our details from the mail trap is here.
All we got to do is simply just replace this one into our mail helper, email helper.
Let's go ahead and change this one.
So this one will be coming up from process dot E and V dot SM SMTP underscore.
Yeah, better to copy that then worry about later on.
So SMTP host and I can actually go ahead and copy this and this one will change to SMTP port again.
There might be some typos eventually that we need to fix up.
And this one is user.
So SMTP user and this one needs to go away and this one is a SMTP password.
So process dot e and v smtp pass.
So all the details are now being controlled by my E and V file, which is using a service known as mail
trap.
And I will be able to see all of the e mails up here.
Again, these are good crafters are some another project.
We don't need to worry too much on that.
We will be getting our again notice here.
Email addresses and all these things are up here.
All you got to do is monitor your inbox.
Right now there are four messages in my inbox.
Hopefully, as we will be sending more, there will be more messages in my inbox.
So there we go.
I can close this one here and email helper.
Okay, one one thing I forgot is pass on this message up here.
Almost forgot that.
So there we go.
Now this message is being used here.
And as soon as the say is transferred or send email, it is going to send me an email.
Some people have seen again, this is a Fred faux fu example.
We need to change this one again.
Let's go ahead and change this one also.
So we're going to go ahead and change this one here.
So this one is usually hardcoded from whatever the website you are using.
So they give you your own emails as well.
So we're going to go ahead and change this one.
So let's go ahead and kind of a hard code, this one.
So hit the ish at the rate ae dev.
Again, these are from emails.
So usually you will also get an account onto a W, s or whatever the website you are using and all these
emails actually generate from your address.
So usually this value is hardcoded or can be controlled by process tab.
So that's it for this one.
Let's go ahead and catch up in the next video.