Email Service
Bunship uses resend and @react-email/components for email functionality
Bunship integrates Resend and @react-email/components to provide email services, supporting verification emails, one-time verification codes, password reset functionality, and responsive email templates.
Setting Up Resend
1. Create an Account
First, you need to create an account on the Resend platform:
- Visit the Resend website and sign up
- Complete email verification
- Create a domain or use Resend's testing domain
2. Obtain API Key
- Log in to the Resend console
- Navigate to the "API Keys" section
- Click the "Create API Key" button
- Name your key and create it
- Copy the generated API key
3. Configure Environment Variables
Add the API key to your project's .env file:
Email Templates
Bunship uses React Email to create responsive email templates, all located in the src/emails/templates directory.
Implemented Email Templates
Bunship has already implemented the following email templates:
- Email Verification - Used to verify user email addresses
- One-Time Verification Code (OTP) - Used for multi-factor authentication or login verification
- Password Reset - Used for password reset workflows
Previewing Email Templates
You can preview email templates locally using the following command:
This will start a local server, typically at http://localhost:3001, where you can view and test all email template renderings in your browser.
Creating Custom Email Templates
You can add custom email templates by creating new React components in the src/emails/templates directory.
Template Example
Here's an example of an email template for sending a one-time verification code:
Sending Emails
Bunship has implemented email sending methods in @/lib/auth. These methods are used for:
- Sending email verification emails
- Sending one-time verification codes
- Sending password reset links
Email Sending Example
Custom Email Components
In addition to creating complete email templates, you can create reusable email components such as headers, buttons, and footers. Bunship provides some common components in the src/emails/components directory.
Creating Custom Components
For example, creating a custom button component:
Troubleshooting
Email Not Sending
- Check if the
RESEND_API_KEYenvironment variable is set correctly - Verify that the sender address is validated on the Resend platform
- Check the Resend console for any sending errors
Email Styling Issues
- Use
bun email:devto preview emails and ensure styles are correct - Different email clients have varying CSS support; use inline styles when possible
- Using React Email's built-in components can improve email compatibility