How to send Email with Node and SendGrid in 5 Minutes

<code class="js">import sendgrid, { mail as helper } from 'sendgrid'

export const sendMail = async (payload) => {
  const {
    from_email,
    to_email,
    subject,
    body
  } = payload;

  const contentType = 'text/html'
  const fromEmail = new helper.Email(from_email)
  const toEmail = new helper.Email(to_email)

  const content = new helper.Content(contentType, body)
  const mail = new helper.Mail(fromEmail, subject, toEmail, content)
  const sg = sendgrid(process.env.SENDGRID_API_KEY)
  const request = sg.emptyRequest({
    method: 'POST',
    path: '/v3/mail/send',
    body: mail.toJSON()
  })
  return await sg.API(request)
}

export default sendMail