Thanks to visit codestin.com
Credit goes to github.com

Skip to content

eibrahim/freeresend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FreeResend

A self-hosted, open-source alternative to Resend for sending transactional emails.

FreeResend allows you to host your own email service using Amazon SES and optionally Digital Ocean for DNS management. It provides a Resend-compatible API so you can use it as a drop-in replacement.

πŸ“° Stay updated: Get the latest frontend development insights delivered weekly with Frontend Weekly - curated by the author of FreeResend!

Features

  • πŸš€ 100% Resend-compatible - True drop-in replacement using environment variables
  • 🏠 Self-hosted - Full control over your email infrastructure
  • πŸ“§ Amazon SES integration - Reliable email delivery with DKIM support
  • 🌐 Automatic DNS setup - Integration with Digital Ocean for DNS record creation
  • πŸ” DKIM authentication - Automatic DKIM key generation and DNS record creation
  • πŸ”‘ API key management - Generate and manage multiple API keys per domain
  • πŸ“Š Email logging - Track all sent emails with delivery status and logs
  • 🎯 Domain verification - Automated domain verification with SES
  • πŸ”’ Secure - JWT-based authentication and robust API key validation
  • 🐳 Docker ready - Containerized deployment with Docker Compose
  • πŸ“ Comprehensive logging - Detailed email logs with webhook support

Quick Start

Prerequisites

  • Node.js 18+
  • PostgreSQL database (local or hosted)
  • Amazon AWS account with SES access
  • Digital Ocean account (optional, for automatic DNS management)

Installation

  1. Clone and install dependencies:
git clone <your-repo>
cd freeresend
npm install
  1. Set up environment variables:
cp .env.local.example .env.local

Edit .env.local with your configuration:

# Next.js Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-super-secret-jwt-key-here

# Database Configuration (PostgreSQL)
DATABASE_URL=postgresql://username:password@hostname:port/database

# AWS SES Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key

# Digital Ocean API Configuration (optional)
DO_API_TOKEN=your-digitalocean-api-token

# Application Configuration
ADMIN_EMAIL=[email protected]
ADMIN_PASSWORD=your-secure-admin-password
  1. Set up the database:

In your Supabase SQL editor, run the contents of database.sql to create all necessary tables.

  1. Start the development server:
npm run dev

Visit http://localhost:3000 and log in with your admin credentials.

AWS SES Setup

  1. Verify your AWS account for SES:

    • Go to AWS SES console
    • Move out of sandbox mode if needed
  • Configure sending limits
  1. Create IAM user with SES permissions:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ses:SendEmail",
        "ses:SendRawEmail",
        "ses:VerifyDomainIdentity",
        "ses:GetIdentityVerificationAttributes",
        "ses:DeleteIdentity",
        "ses:CreateConfigurationSet",
        "ses:VerifyDomainDkim",
        "ses:GetIdentityDkimAttributes"
      ],
      "Resource": "*"
    }
  ]
}

Note: The DKIM permissions (ses:VerifyDomainDkim, ses:GetIdentityDkimAttributes) are required for automatic DKIM setup.

Digital Ocean DNS Setup (Optional)

If you want automatic DNS record creation:

  1. Create a Digital Ocean API token with read/write access
  2. Add your domains to Digital Ocean's DNS management
  3. Set the DO_API_TOKEN environment variable

Using FreeResend with Resend SDK

FreeResend is 100% compatible with the Resend Node.js SDK!

Method 1: Environment Variable (Recommended)

Set the RESEND_BASE_URL environment variable:

export RESEND_BASE_URL="https://your-freeresend-domain.com/api"

Then use Resend exactly as before:

import { Resend } from "resend";

// No changes needed - FreeResend API key works with Resend SDK!
const resend = new Resend("your-freeresend-api-key");

const { data, error } = await resend.emails.send({
  from: "[email protected]",
  to: ["[email protected]"],
  subject: "Hello World",
  html: "<strong>it works!</strong>",
});

Method 2: Direct API

const response = await fetch("https://your-freeresend-domain.com/api/emails", {
  method: "POST",
  headers: {
    Authorization: "Bearer your-freeresend-api-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    from: "[email protected]",
    to: ["[email protected]"],
    subject: "Hello World",
    html: "<strong>it works!</strong>",
  }),
});

API Endpoints

Authentication

  • POST /api/auth/login - Login with email/password
  • GET /api/auth/me - Get current user info

Domains

  • GET /api/domains - List all domains
  • POST /api/domains - Add new domain
  • DELETE /api/domains/{id} - Delete domain
  • POST /api/domains/{id}/verify - Check domain verification

API Keys

  • GET /api/api-keys - List API keys
  • POST /api/api-keys - Create new API key
  • DELETE /api/api-keys/{id} - Delete API key

Emails (Resend-compatible)

  • POST /api/emails - Send email
  • GET /api/emails/logs - Get email logs
  • GET /api/emails/{id} - Get specific email

Webhooks

  • POST /api/webhooks/ses - SES webhook endpoint

Domain Setup Process

  1. Add domain in the FreeResend dashboard

  2. DNS Records will be automatically created (if Digital Ocean is configured) or displayed for manual setup:

    • TXT record - _amazonses.yourdomain.com for SES domain verification
    • MX record - yourdomain.com for receiving emails via SES
    • SPF record - yourdomain.com for sender policy framework
    • DMARC record - _dmarc.yourdomain.com for email authentication policy
    • DKIM records - 3 CNAME records for *._domainkey.yourdomain.com for email signing
  3. Verify domain - Click "Check Verification" once DNS records are live

  4. Create API key - Generate API keys for your verified domain

  5. Start sending - Use the API key with FreeResend or Resend SDK

Testing Your Setup

FreeResend includes test scripts to verify your installation:

Quick Test

# Test with cURL (update variables in script first)
./test-curl.sh

Comprehensive Test

# Test direct API + Resend SDK compatibility + Email logs
node test-email.js

Both scripts will:

  • βœ… Send test emails using your API key
  • βœ… Verify Resend SDK compatibility
  • βœ… Check email logs functionality
  • πŸ“§ Send actual emails to your inbox for verification

Troubleshooting

Common Issues

Q: Getting "Invalid API key" errors

  • βœ… Make sure you copied the complete API key from the green success message (not the masked version from the table)
  • βœ… API keys have format: frs_keyId_secretPart (3 parts separated by underscores)

Q: Digital Ocean DNS automation not working

  • βœ… Verify your DO API token has Read & Write access to Domains and Domain Records
  • βœ… Ensure your domain is added to Digital Ocean's DNS management
  • βœ… Test token: curl -H "Authorization: Bearer YOUR_TOKEN" https://api.digitalocean.com/v2/domains

Q: Domain verification stuck at "pending"

  • βœ… DNS propagation takes 5-30 minutes - be patient!
  • βœ… Check DNS records: dig TXT _amazonses.yourdomain.com
  • βœ… Ensure all DNS records are created properly

Q: AWS SES permissions error

  • βœ… Make sure your IAM policy includes DKIM permissions: ses:VerifyDomainDkim and ses:GetIdentityDkimAttributes
  • βœ… Verify your AWS account is out of SES sandbox mode

Q: Resend SDK not working with FreeResend

  • βœ… Set environment variable: export RESEND_BASE_URL="https://your-domain.com/api"
  • βœ… Use FreeResend API key (starts with frs_), not Resend API key

Production Deployment

Docker (Recommended)

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]

Environment Setup

  • Use a production database (Supabase Pro or self-hosted PostgreSQL)
  • Set up proper SSL certificates
  • Configure firewall rules
  • Set up monitoring and logging
  • Configure SES with proper sending limits

Vercel Deployment

FreeResend can be deployed on Vercel with some configuration:

  1. Connect your GitHub repo to Vercel
  2. Set environment variables in Vercel dashboard
  3. Deploy

Note: Webhook endpoints might need special configuration for Vercel's serverless environment.

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Lint code
npm run lint

Repository Structure

freeresend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                 # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ api/            # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/       # Authentication endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ domains/    # Domain management
β”‚   β”‚   β”‚   β”œβ”€β”€ api-keys/   # API key management
β”‚   β”‚   β”‚   β”œβ”€β”€ emails/     # Email sending & logs
β”‚   β”‚   β”‚   └── webhooks/   # SES webhook handlers
β”‚   β”‚   β”œβ”€β”€ globals.css     # Global styles
β”‚   β”‚   β”œβ”€β”€ layout.tsx      # Root layout
β”‚   β”‚   └── page.tsx        # Main dashboard page
β”‚   β”œβ”€β”€ components/         # React components
β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx   # Main dashboard
β”‚   β”‚   β”œβ”€β”€ LoginForm.tsx   # Authentication
β”‚   β”‚   └── *Tab.tsx        # Tab components
β”‚   β”œβ”€β”€ contexts/           # React contexts
β”‚   └── lib/                # Core business logic
β”‚       β”œβ”€β”€ supabase.ts     # Database client
β”‚       β”œβ”€β”€ auth.ts         # Authentication logic
β”‚       β”œβ”€β”€ ses.ts          # Amazon SES integration
β”‚       β”œβ”€β”€ digitalocean.ts # DNS automation
β”‚       β”œβ”€β”€ domains.ts      # Domain management
β”‚       β”œβ”€β”€ api-keys.ts     # API key logic
β”‚       └── middleware.ts   # API middleware
β”œβ”€β”€ database.sql            # Database schema
β”œβ”€β”€ docker-compose.yml      # Development setup
β”œβ”€β”€ test-email.js          # Comprehensive test script
β”œβ”€β”€ test-curl.sh           # Quick cURL test
└── README.md              # This file

Contributing

We welcome contributions! Here's how to get started:

Development Setup

  1. Fork the repository on GitHub
  2. Clone your fork: git clone https://github.com/eibrahim/freeresend.git
  3. Install dependencies: npm install
  4. Set up environment following the Quick Start guide above
  5. Run tests: node test-email.js
  6. Start development: npm run dev

Contributing Guidelines

  • πŸ› Bug fixes - Always welcome with test cases
  • ✨ New features - Open an issue first to discuss
  • πŸ“ Documentation - Improvements always appreciated
  • πŸ§ͺ Tests - Required for new features
  • πŸ’» Code style - Follow existing patterns

Pull Request Process

  1. Create a feature branch: git checkout -b feature/your-feature-name
  2. Make your changes with clear, descriptive commits
  3. Add tests for new functionality
  4. Update documentation if needed
  5. Submit a pull request with a clear description

Reporting Issues

When reporting bugs, please include:

  • Your environment (Node.js version, OS, etc.)
  • Steps to reproduce the issue
  • Expected vs actual behavior
  • Relevant error messages or logs

License

MIT License - see LICENSE file for details.

Support

  • πŸ“– Documentation: Check SETUP.md for detailed setup instructions
  • πŸ› Issues: Report bugs via GitHub Issues
  • πŸ’‘ Feature Requests: Suggest improvements via GitHub Issues
  • πŸš€ Professional Support: Custom development and enterprise support available via EliteCoders

Roadmap

  • Email templates support
  • Webhook retry mechanism
  • Email analytics dashboard
  • Multi-user support
  • Email scheduling
  • SMTP server support
  • Email campaign management

About the Author

FreeResend is built and maintained by Emad Ibrahim - a software engineer and entrepreneur passionate about creating developer tools and open-source solutions.

πŸ‘¨β€πŸ’» Connect with Emad

  • 🐦 Twitter: @eibrahim - Follow for updates on FreeResend and web development insights
  • πŸ“§ Email: [email protected]
  • πŸ“° Newsletter: Frontend Weekly - The best frontend development articles delivered weekly
  • πŸ’Ό Professional Services: Custom development and enterprise support via EliteCoders

πŸš€ Need Custom Development?

If you need help with:

  • πŸ—οΈ Custom email infrastructure modifications
  • πŸš€ Enterprise deployments and scaling
  • πŸ”§ Integration with your existing systems
  • 🎯 Feature development beyond the roadmap

Get in touch with EliteCoders β†’

Building powerful software solutions for businesses worldwide 🌎

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published