← View All Guides
SendGrid logo
Integration Guide

How to Send Referral Transactional Emails with SendGrid + GrowSurf

Deliver high-priority referral notification emails through SendGrid's transactional email infrastructure.

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.

Integration Steps

Step 1: Set Up SendGrid for Transactional Email

Configure your SendGrid account for sending referral transactional emails.

  • Create a SendGrid account or use your existing one
  • Authenticate your sending domain in Settings > Sender Authentication (DNS records: CNAME, DKIM, SPF)
  • Create a dedicated API Key with "Mail Send" permissions in Settings > API Keys
  • Set up a dedicated IP address for transactional emails (separates from marketing sends for better deliverability)

Step 2: Create Dynamic Email Templates

Build SendGrid dynamic templates for each referral email type.

  • Go to Email API > Dynamic Templates > Create Template
  • Create templates for:
    • "Referral Welcome" β€” sent when someone joins the program
    • "Referral Notification" β€” sent to referrer when friend signs up
    • "Referral Converted" β€” sent when a referral converts to a customer
    • "Reward Earned" β€” sent when a reward is ready to claim
  • Use SendGrid's design editor or code editor for each template
  • Include dynamic Handlebars variables: {{firstName}}, {{referralLink}}, {{referralCount}}

Step 3: Build the Webhook-to-SendGrid Handler

Create a server endpoint that receives GrowSurf events and sends the appropriate SendGrid email.

  • Listen for GrowSurf webhook events
  • Map each event type to a SendGrid template ID
  • Populate template variables from the webhook payload
  • Send via SendGrid's Mail Send API: POST /v3/mail/send

Step 4: Implement Personalization with Dynamic Data

Use SendGrid's Handlebars templating to personalize each email with referral-specific data.

  • Pass referral data as dynamic_template_data in the API call
  • Use conditionals in templates: {{#if referralCount}}You've referred {{referralCount}} friends!{{/if}}
  • Use iterators for showing multiple referrals: {{#each recentReferrals}}...{{/each}}
  • Personalize the subject line with dynamic data for higher open rates

Step 5: Track Email Performance

Monitor referral email deliverability and engagement using SendGrid's analytics.

  • Enable click tracking and open tracking in Settings > Mail Settings
  • Use SendGrid's Activity Feed to monitor individual email delivery status
  • Track metrics by template: delivery rate, open rate, click rate, bounce rate
  • Set up SendGrid Event Webhooks to receive delivery events in your system

Step 6: Optimize for Maximum Deliverability

Ensure your referral emails consistently reach the inbox, not the spam folder.

  • Keep transactional referral emails separate from marketing emails (use separate subusers or IPs)
  • Don't include unsubscribe links in transactional emails (they're event-triggered, not marketing)
  • Monitor your sender reputation score in Settings > Sender Reputation
  • Handle bounces immediately: remove bounced addresses from future sends

Code Snippets

// 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 });
});

Tips

Use Categories for Granular Analytics

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.

Implement Suppression Groups for Referral Emails

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.

Send Within 30 Seconds for Maximum Impact

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.

FAQ

Should I use SendGrid's SMTP relay or Web API for referral emails?

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.

How do I handle SendGrid rate limits for high-volume referral programs?

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.

Can I A/B test referral email templates in SendGrid?

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.

Set up your refer a friend program with customer referral and affiliate program software that lowers your acquisition costs, increases customer loyalty, and saves you gobs of time.

Trusted by marketing and product teams at fast-growing B2C, fintech, and SaaS companies