DEV Community

Discussion on: Using Netlify lambda functions to send emails from a GatsbyJS site

miguelmota profile image
Miguel Mota • Edited on

You can move the environment variable code to outside the handler since there's no need to re-set the sendgrid config on every invocation.

const sgMail = require('@sendgrid/mail')

const { SENDGRID_API_KEY, SENDGRID_TO_EMAIL } = process.env

exports.handler =  async (event, context, callback) => {
 // ..
char_bone profile image
Charlotte Author

Great catch, thank you! I'll get that updated :)