title: NodeJS Sendgrid 401 unauthorized
body: <p>After registering a user in my node express server, I would like to send a verification email. If the user is created I use this function to send the email:</p>
  <pre><code>import dotenv from 'dotenv'
  import sgMail from '@sendgrid/mail'
  
  sgMail.setApiKey(process.env.SENDGRID_API_KEY)
  
  const sendEmail = (to, token) =&gt; {
      const msg = {
          to,
          from: process.env.SENDGRID_SENDER,
          subject: 'Email Verification',
          text: `Please click the following link: http://localhost:5000/${token}`
      }
      
      sgMail
       .send(msg)
       .then((response) =&gt; {
          console.log(response[0].statusCode)
          console.log(response[0].headers)
      })
       .catch((error) =&gt; {
          console.error(error)
      })
  }
  
  export { sendEmail }
  </code></pre>
  <p>It is called here:</p>
  <pre><code>const registerUser = asyncHandler(async (req, res) =&gt; {
    const { name, email, password } = req.body
  
    const userExists = await User.findOne({ email })
  
    if (userExists) {
      res.status(400)
      throw new Error('User already exists')
    }
  
    const user = await User.create({
      name,
      email,
      password
    })
  
    if (user) {
      sendEmail(user.email, user.token) //HERE
      res.status(201).json({
        _id: user._id,
        name: user.name,
        email: user.email,
        isAdmin: user.isAdmin,
        isVerified: user.isVerified,
        token: generateToken(user._id),
      })
    } else {
      res.status(400)
      throw new Error('Invalid user data')
    }
  })
  </code></pre>
  <p>The problem I am having is I get a ResponseError Unauthorized (code 401) when the request is made. The user does get created in the system. On my sendgrid account, I have verified the sender email with full access and I am storing my API Key in my .env file.</p>
  <p>I have used 10 minute mail accounts to test this and real email accounts.</p>