PitchHut logo
Forward emails seamlessly to Cloudflare without external providers.
Pitch

This project provides a lightweight SMTP server to connect your applications to Cloudflare's Workers, allowing email sending without any external SMTP providers. Key features include free usage via Cloudflare's tier, rate limiting, automatic retries, and support for attachments, making it an ideal solution for efficient email handling.

Description

SMTP to Cloudflare Webhook Bridge

The SMTP to Cloudflare Webhook Bridge is a lightweight SMTP server designed to forward emails to a Cloudflare Worker. This project utilizes 100% Cloudflare infrastructure, eliminating the need for external SMTP providers. This is ideal for applications such as automation tools or custom services requiring email functionalities without the overhead of maintaining an external email server.

Architecture Overview

The architecture consists of an application communicating with the SMTP Bridge via SMTP, which then forwards emails over HTTPS to a Cloudflare Email Worker. The following figure illustrates the flow:

┌─────────────┐      SMTP       ┌──────────────┐      HTTPS      ┌─────────────────┐
│  Your App   │ ──────────────► │ SMTP Bridge  │ ──────────────► │ Cloudflare      │
│  (n8n, etc) │   Port 2525     │  (Node.js)   │    Webhook      │ Email Worker    │
└─────────────┘                 └──────────────┘                 └────────┬────────┘
                                       │                                  │
                                       ▼                                  ▼
                              ┌─────────────────┐                ┌─────────────────┐
                              │  Health Check   │                │ Email Recipient │
                              │  :2526/health   │                └─────────────────┘
                              └─────────────────┘

Key Features

  • Fully Cloudflare-Based: Operates without reliance on external email services.
  • Cost-Effective: Utilizes Cloudflare's free tier, allowing for up to 200 emails per day at no cost.
  • Rate Limiting: Includes safeguards against quota exhaustion.
  • Email Queue & Retries: Features an SQLite-backed queue system that automatically manages retries for failed email deliveries.
  • Multiple Recipient Support: Allows sending to multiple recipients via TO, CC, or BCC fields.
  • File Attachments: Supports attaching files using Base64 encoding.
  • Monitoring Capabilities: Provides health check endpoints for seamless monitoring.
  • Container Ready: Compatible with Docker for simplified deployment.

Configuration Requirements

SMTP Bridge Configuration (.env)

VariableRequiredDefaultDescription
WEBHOOK_URLYes-URL of the Cloudflare Worker
WEBHOOK_API_KEYYes-API key for secure requests
SMTP_PORTNo2525Port for SMTP communication
SMTP_HOSTNo127.0.0.1Host address for the bridge
RATE_LIMIT_PER_DAYNo200Maximum emails sent per day

Health Check Endpoints

The bridge provides HTTP endpoints for health monitoring:

EndpointDescription
GET /healthRetrieves overall health status and metrics
GET /statsDisplays rate limit and queue statistics

Example Response

To check health status, you can use:

curl http://localhost:2526/health

Response will include the server's health status and rate limit details.

Email Sending Examples

Sending Emails with Nodemailer

const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
  host: '127.0.0.1',
  port: 2525,
  secure: false
});

await transporter.sendMail({
  from: 'app@yourdomain.com',
  to: 'user@example.com',
  subject: 'Hello',
  text: 'Hello World!'
});

The SMTP Bridge facilitates a seamless integration of email sending functionalities directly through the Cloudflare ecosystem, offering an efficient, reliable solution for those who prefer to leverage Cloudflare's infrastructure for their email communications.

0 comments

No comments yet.

Sign in to be the first to comment.