Built for startups,
scaled for unicorns
Successfully submitted!
Error! Please try again
Referral notification emails β reward confirmations, referral alerts, and welcome messages β are transactional in nature: they're triggered by specific actions and need to be delivered reliably and quickly. SendGrid's transactional email API is purpose-built for this, offering high deliverability, detailed analytics, and template management that generic marketing email tools can't match.
This guide covers setting up SendGrid to deliver referral program transactional emails triggered by GrowSurf events. You'll learn how to configure SendGrid's API for referral emails, build dynamic templates with referral data, track email performance, and ensure maximum deliverability for your most important referral communications.
Configure your SendGrid account for sending referral transactional emails.
Build SendGrid dynamic templates for each referral email type.
{{firstName}}, {{referralLink}}, {{referralCount}}Create a server endpoint that receives GrowSurf events and sends the appropriate SendGrid email.
POST /v3/mail/sendUse SendGrid's Handlebars templating to personalize each email with referral-specific data.
dynamic_template_data in the API call{{#if referralCount}}You've referred {{referralCount}} friends!{{/if}}{{#each recentReferrals}}...{{/each}}Monitor referral email deliverability and engagement using SendGrid's analytics.
Ensure your referral emails consistently reach the inbox, not the spam folder.
// Send referral transactional emails via SendGrid
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const TEMPLATES = {
PARTICIPANT_CREATED: 'd-welcome123', // Welcome template ID
PARTICIPANT_REFERRED: 'd-notification456', // Referral notification template
CAMPAIGN_REFERRAL_CONVERTED: 'd-converted789', // Conversion celebration
PARTICIPANT_REACHED_REWARD: 'd-reward012' // Reward earned
};
async function sendReferralEmail(event, participant, referrer) {
const templateId = TEMPLATES[event];
if (!templateId) return;
// Determine recipient based on event type
let recipientEmail, templateData;
if (event === 'PARTICIPANT_CREATED') {
recipientEmail = participant.email;
templateData = {
firstName: participant.firstName || 'there',
referralLink: participant.shareUrl,
referralCode: participant.referralCode,
rewardDescription: '$10 credit for each friend who signs up'
};
} else if (event === 'PARTICIPANT_REFERRED') {
recipientEmail = referrer.email; // Notify the referrer
templateData = {
firstName: referrer.firstName || 'there',
friendName: participant.firstName || participant.email,
referralCount: referrer.referralCount,
referralLink: referrer.shareUrl,
nextRewardAt: getNextRewardThreshold(referrer.referralCount)
};
}
const msg = {
to: recipientEmail,
from: { email: '[email protected]', name: 'YourCompany Referrals' },
templateId: templateId,
dynamicTemplateData: templateData,
categories: ['referral-program', event.toLowerCase()],
customArgs: {
referral_code: participant.referralCode,
event_type: event
}
};
await sgMail.send(msg);
}
app.post('/webhooks/growsurf/email', async (req, res) => {
const { event, participant, referrer } = req.body;
await sendReferralEmail(event, participant, referrer);
res.json({ success: true });
});Add SendGrid categories to every referral email: a general "referral-program" category and a specific event category (e.g., "referral-notification"). This lets you view aggregate referral email performance and drill down into specific email types in SendGrid's Statistics dashboard.
While referral emails are transactional, create a SendGrid suppression group for referral notifications. This lets users opt out of referral alerts without affecting critical transactional emails like password resets or receipts. Respecting preferences builds trust with your most engaged users.
Referral notification emails have the highest impact when delivered within 30 seconds of the event. Optimize your webhook handler for speed β minimize database calls and external API lookups before the SendGrid send. Process analytics and logging asynchronously after the email is sent.
Use the Web API (v3) for referral emails. It's faster, more reliable, and supports dynamic templates. SMTP relay is better for legacy applications that can't make HTTP calls. The Web API also provides immediate feedback on send status and supports advanced features like categories and custom arguments.
SendGrid's free tier allows 100 emails/day. Paid plans support up to 100,000 emails/day. For high-volume programs, use SendGrid's batch sending feature to send up to 1,000 personalizations per API call. Implement a queue that batches emails for efficient delivery.
SendGrid's dynamic templates don't have built-in A/B testing. Implement your own: create two template versions, randomly assign each referral event to version A or B in your webhook handler, and track open/click rates by template version using categories. After enough data, promote the winner.
Trusted by marketing and product teams at fast-growing B2C, fintech, and SaaS companies
