title: how to send email confirmation in nodejs and SendGrid?
body: <p>I have a NodeJs and ReactJs project, where a user can <strong>register</strong> and after the user is registered they will get an email to confirm their account.</p>
  <p>so now when I register the email is working well. but it works with an email that I set in like this.</p>
  <pre><code>function sendMail() {
    const msg = {
      to: &quot;someoneemail@gmail.com&quot;, 
      from: &quot;myemail@gmail.com&quot;, 
      subject: &quot;a subject&quot;,
      text: &quot;some text herer&quot;,
      html: &quot;&lt;strong&gt;and easy to do anywhere, even with Node.js&lt;/strong&gt;&quot;,
    };
    sgMail
      .send(msg)
      .then(() =&gt; {
        console.log(&quot;Email sent&quot;);
      })
      .catch((error) =&gt; {
        console.error(error);
      });
  }
  
  module.exports = { sendMail };
  </code></pre>
  <p><strong>I need to remove this</strong> <code>to: &quot;someoneemail@gmail.com&quot;</code> a*</p>
  <ol>
  <li><p>nd instead set the user email, the user who to register on this
  system</p>
  </li>
  <li><p>and instead of <code>text:</code> i have to send the <strong>token</strong>.</p>
  </li>
  </ol>
  <p>so here is the registration part:</p>
  <pre><code>router.post(&quot;/register&quot;, async (req, res) =&gt; {
    const { fullName, emailAddress, password } = req.body;
    const user = await Users.findOne({
      where: {
        [Op.and]: [{ fullName: fullName }, { emailAddress: emailAddress }],
      },
    });
  
    if (user) {
      res.status(400).send({
        error: `some message.`,
      });
    } else {
      bcrypt
        .hash(password, 10)
        .then((hash) =&gt; {
          return {
            fullName: fullName,
            emailAddress: emailAddress,
            password: hash,
            isVerified: false,
          };
        })
        .then((user) =&gt; {
          const token = TokenGenerator.generate();
          const creator = Verifications.belongsTo(Users, { as: &quot;user&quot; });
          return Verifications.create(
            {
              token,
              user: user,
            },
            {
              include: [creator],
            }
          );
        })
        .then((verification) =&gt; {
          console.log(&quot;verification&quot;, verification);
          sendMail();
        })
        .then(() =&gt; res.json(&quot;User, Successmessage &quot;));
    }
  });
  </code></pre>
  <p>but the codes are not in the same file.</p>