patterntypescriptModerate
SendGrid / Resend Transactional Email Sending
Viewed 0 times
resend v3
resendsendgridtransactional emailSPFDKIMDMARCdomain verificationemail deliverability
Error Messages
Problem
Sending transactional emails (welcome, reset password, receipts) requires an email API with proper SPF/DKIM configuration. Direct SMTP or using a misconfigured sender domain results in emails landing in spam.
Solution
Use Resend (simpler API) or SendGrid with a verified sending domain. Authenticate the domain with SPF, DKIM, and DMARC records. Send from a subdomain (mail.yourdomain.com) to protect the root domain's reputation.
Why
Email deliverability depends on domain reputation and authentication records. SPF authorizes sending IP addresses. DKIM proves the email was not tampered with. DMARC instructs receivers on how to handle failures. ESPs manage IP reputation at scale.
Gotchas
- Never send from @gmail.com or @outlook.com as your From address via an ESP — use your own verified domain
- Resend requires the domain to be verified in its dashboard before sending — unverified domains are silently rejected
- Include both text/plain and text/html versions to improve deliverability and accessibility
- Rate-limit password reset and magic link emails per address to prevent email flooding
Code Snippets
Sending email with Resend
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY!);
export async function sendWelcomeEmail(to: string, name: string) {
const { data, error } = await resend.emails.send({
from: 'welcome@mail.myapp.com', // verified domain
to,
subject: `Welcome to MyApp, ${name}!`,
html: `<p>Hi ${name}, thanks for signing up!</p>`,
text: `Hi ${name}, thanks for signing up!`,
});
if (error) {
console.error('Failed to send email:', error);
throw new Error('Email delivery failed');
}
return data;
}Revisions (0)
No revisions yet.