Integrations

Resend Email Setup

Configure Resend for email functionality

Overview

OpenInvoice uses Resend for sending transactional emails including invoices, payment confirmations, and reminders.

Prerequisites

  • Resend account (sign up here)
  • Domain verified (optional, recommended for production)

Setup Steps

1. Get API Key

  1. Go to Resend Dashboard
  2. Click Create API Key
  3. Copy the API key (starts with re_)

2. Configure Environment Variables

RESEND_API_KEY=re_...
RESEND_FROM_EMAIL=noreply@yourdomain.com
RESEND_FROM_NAME=OpenInvoice

3. Verify Domain (Production)

  1. Go to Domains in Resend Dashboard
  2. Click Add Domain
  3. Add your domain
  4. Add DNS records:
    • SPF record
    • DKIM record
    • DMARC record (optional)
  5. Verify domain

Webhook Setup

1. Create Webhook

  1. Go to Webhooks in Resend Dashboard
  2. Click Add Webhook
  3. Enter URL:
    • Development: http://localhost:3000/api/webhooks/resend (use ngrok)
    • Production: https://yourdomain.com/api/webhooks/resend

2. Subscribe to Events

Select events:

  • email.sent
  • email.delivered
  • email.delivery_delayed
  • email.complained
  • email.bounced
  • email.opened
  • email.clicked

3. Get Webhook Secret

  1. Copy the Signing Secret
  2. Add to environment:
RESEND_WEBHOOK_KEY=whsec_...

Usage

Sending Emails

import { Resend } from 'resend';

const resend = new Resend(process.env.RESEND_API_KEY);

await resend.emails.send({
  from: process.env.RESEND_FROM_EMAIL!,
  to: customerEmail,
  subject: 'Invoice #123',
  html: emailTemplate,
  attachments: [
    {
      filename: 'invoice.pdf',
      content: pdfBuffer,
    },
  ],
});

Email Templates

OpenInvoice includes HTML email templates for:

  • Invoice emails
  • Payment confirmations
  • Payment reminders
  • General notifications

Email Tracking

Tracking Events

Resend webhooks provide:

  • Email Sent - Email was sent
  • Email Delivered - Delivered to recipient
  • Email Opened - Recipient opened email
  • Email Clicked - Recipient clicked link
  • Email Bounced - Delivery failed
  • Email Complained - Marked as spam

Storing Events

Events are stored in the database:

  • EmailLog - Email records
  • EmailEvent - Individual events

Testing

Development

  1. Use Resend test mode
  2. Send test emails
  3. Verify webhook events
  4. Check email delivery

Production

  1. Verify domain
  2. Use production API key
  3. Test email delivery
  4. Monitor bounce rates

Troubleshooting

Emails Not Sending

  • Verify API key is correct
  • Check from email is verified
  • Review Resend Dashboard logs
  • Verify domain (if using custom domain)

Webhook Not Receiving Events

  • Verify webhook URL is accessible
  • Check webhook secret matches
  • Review webhook logs in Resend Dashboard
  • Test with ngrok locally

Best Practices

  1. Verify Domain - Use verified domain for production
  2. Monitor Bounces - Track bounce rates
  3. Handle Errors - Implement error handling
  4. Test Templates - Test email rendering
  5. Track Engagement - Monitor opens and clicks

Next Steps