// Make sure you have added @sendgrid/mail to your Node.js project. // // Example Usage: // API_KEY=SG.123456789 CUSTOM_URL=https://www.example.com?campaign_id=my-campaign RECIPIENT_EMAIL=johndoe@gmailx.com node index.js const sgMail = require('@sendgrid/mail') sgMail.setApiKey(process.env.API_KEY) const text = `Please click this link for my email campaign: ${process.env.CUSTOM_URL}` const html = `Please click for my email campaign.` const msg = { to: process.env.RECIPIENT_EMAIL, from: 'example@example.com', // CHANGE THIS TO USE YOUR SENDGRID VERIFIED SENDER subject: 'SendGrid Test Email with campaign link', text, html } sgMail .send(msg) .then((response) => { console.log(response[0].statusCode) console.log(response[0].headers) }) .catch((error) => { console.error(error) })