Resend Integration
Resend is an email API designed specifically for developers that simplifies the process of sending, tracking, and managing transactional emails. It helps developers focus on building applications without diving into the complexities of email infrastructure.
In the Nexty.dev template, we use Resend to implement two features:
- Email subscription and notifications
- Email notifications for payment failures
You can easily use these two features as a reference to implement Resend API for sending emails in other parts of your application.
Beyond sending emails through the API, Resend also offers a Broadcast feature in its dashboard for sending marketing emails. If you registered for Nexty.dev's waitlist early, you definitely received an early bird offer email sent through Broadcast on April 29th.
Next, I'll introduce the integration process of Resend in the Nexty.dev template.
Registration and Basic Configuration
-
Visit Resend and sign up with your email
-
Go to the API Keys page and create an API Key
-
Add the API Key to your template's environment variables as
RESEND_API_KEY
-
Next, open the Domains page and add your domain name
- Add DNS records
The best practice flow for configuring the _dmarc
record is as follows:
- Initial Stage (Initial Monitoring): Start with
v=DMARC1; p=none; rua=mailto:[email protected]; ruf=mailto:[email protected]; pct=100
and monitor reports. This allows you to view your email sending status and identify issues that might cause email failures without affecting email delivery. Analyze aggregate reports to understand which emails fail SPF and DKIM verification. - Intermediate Stage (Quarantine): After you're confident about your email sending situation, change the policy to
v=DMARC1; p=quarantine; rua=mailto:[email protected]; ruf=mailto:[email protected]; pct=100
. This will quarantine emails that fail verification into spam folders. - Final Stage (Reject): After you're completely certain your email sending configuration is correct, change the policy to
v=DMARC1; p=reject; rua=mailto:[email protected]; ruf=mailto:[email protected]; pct=100
. This will reject emails that fail verification. This is the most secure setting and provides maximum protection for your domain.
rua
and ruf
need to be replaced with your email addresses that will receive email sending reports.
The main purpose of configuring _dmarc
is to prevent external attacks, stopping attackers from spoofing your domain to send phishing emails, malware, or spam.
Once all DNS records pass verification, the Status will show Verified
.
Good to know:
If the Status doesn't update for a long time, you can try clicking
Restart
.
- Now go to the Audiences page and copy the Audience ID to your environment variables as
RESEND_AUDIENCE_ID
Verification
Now you can try submitting an email subscription through the page Footer and verify the following:
- Check the Emails page in the Resend dashboard to view email sending status
- Check the Audiences page in the Resend dashboard to verify Audience additions
- Check the Logs page in the Resend dashboard to review email sending logs
- Check the submitted email address to verify receipt of notification emails sent via API
In the Nexty.dev template, I've also built in a rate limiter implemented with Upstash Redis, and provided a usage example in the email subscription feature. In the next chapter, we'll complete the Upstash configuration to make the rate limiter functional.