Mailer Madness, (React frontend + AWS lambda/SendGrid)

const express = require('express');
const app = express();
require('dotenv').config()
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SECRET_KEY);
const msg = {
to: "jack.sanders.xyz@gmail.com",
from: "jack.sanders.xyz@gmail.com",
subject: "heyy, I hope this works dude",
text: "whats up with this guy lolololol",
html: "<strong>the node email works okay hahaha please bro</strong>"
}
app.get('/', (request, response) => {
sgMail.send(msg)
response.json({ returnMessage: "check your email!!!" })
})
app.listen(4000)
  • step 2, make a new lambda function… call it (myEmailFunction) or whatever. Then save your key in Lambdas environment variables (here)…
  • step 3, Locally make a directory, install your dependencies (node and sendgrid), and write your function for sending the email! here is my directory. What you’re going to do is zip this file, give it to lambda and with it goes your dependencies (how to do this here).
$ npm init --y
$ npm i @sendgrid/mail
$ zip -r <nameOfYourZipFile>.zip ./
return {    
statusCode,
headers: {
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "OPTIONS,POST"
},

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jack Callaway Sanders

Jack Callaway Sanders

A Fullstack Web Dev-arino, part time ‘cool guy’. My website is https://jacksanders.xyz