
Prerequisites
Verified Domain
Make sure you have a verified domain added in AutoSend to send emails from.
API Key
Create a new API key for SMTP authentication or use the existing one.
Installation
Install Better Auth in your project if you haven’t already:Integration
1
Set Environment Variables
Add the required environment variables to your
.env file:.env
Get your API key from the API Keys page in your AutoSend dashboard.
2
Create AutoSend Email Helper
Create a helper function to send emails via the AutoSend API using templates:
lib/autosend.ts
3
Create Email Templates
Create email templates in your AutoSend dashboard for each authentication flow:
Learn more about template variables.
| Template | Suggested ID | Variables |
|---|---|---|
| Email verification | tmpl_verify_email | {{userName}}, {{verificationUrl}} |
| Password reset | tmpl_password_reset | {{userName}}, {{resetUrl}} |
| Sign-in OTP | tmpl_otp_signin | {{otp}} |
| Verification OTP | tmpl_otp_verify | {{otp}} |
| Password reset OTP | tmpl_otp_reset | {{otp}} |
4
Configure Better Auth
Wire up your Better Auth configuration to send emails through AutoSend:
lib/auth.ts
Serverless Considerations
When running on serverless platforms (Vercel, AWS Lambda, Cloudflare Workers), ensure email sending completes before the function terminates.- Vercel
- Cloudflare Workers
Use
waitUntil to ensure the email is sent:Troubleshooting
Domain not verified
Domain not verified
If you receive a “Domain not verified” error, ensure your sending domain is properly configured in AutoSend.Solution: Go to your Domain Settings and complete the DNS verification process.
Invalid API key
Invalid API key
A 401 error indicates your API key is invalid or missing.Solution:
- Check your
.envfile has the correctAUTOSEND_API_KEY - Verify the key in your API Keys dashboard
- Ensure the key hasn’t been revoked
Rate limit exceeded
Rate limit exceeded
If you’re sending too many emails, you may hit rate limits.Solution: Review the Rate Limits documentation and implement appropriate throttling in your application.
Email not delivered
Email not delivered
If emails aren’t being delivered:
- Check the Email Activity dashboard for delivery status
- Verify the recipient email is valid
- Check if the email is in Suppressions
- Review the Troubleshooting Guide for common issues
Next Steps
Email Templates
Create reusable, personalized email templates for transactional emails.
Webhooks
Use webhooks to notify your application about email and contact events in real-time.
Sending Domain
Here’s a step-by-step guide on how to verify and authenticate domain on AutoSend for sending
emails.
Email Activity
Track delivery, performance, and troubleshoot issues for your transactional emails.