import catchErrors from '../../middleware/catchErrors' ; import { NextApiRequest , NextApiResponse } from 'next' ; import { StatusCodes } from 'http-status-codes' ; import sgMail from '@sendgrid/mail' ; import { MailDataRequired } from '@sendgrid/helpers/classes/mail' ; EXPORTS export { sendEmail } ; POST function param { NextApiRequest } req param { NextApiResponse } res returns { undefined } const sendEmail = catchErrors ( async ( req , res ) : Promise < void > => { const { name , email , message } = req . body ; sgMail . setApiKey ( process . env . SENDGRID_API_KEY ! ) ; const msg = { to : process . env . GOOGLE_EMAIL_ADDRESS ! , from : process . env . GOOGLE_EMAIL_ADDRESS ! , subject : `Message from ${ name }` , html : `<h1>${ name }</h1>\n 
			<h3>left message:</h3> \n
      <h4><i>${ message }</i></h4>\n
      <h3>Contact info</h3>
      <h2>Email - ${ email }</h2>
    ` , } ; await sgMail . send ( msg ) ; res . status ( StatusCodes . OK ) . json ( { success : true , } ) ; } ) ;