Skip to content

bitbetterde/mail-forwarder-as-new

Repository files navigation

Mail Forwarder (as New)

A Node.js application that automatically forwards emails from one email account to another using IMAP and SMTP protocols (as a new mail). This allows us to forward emails to a single mail address, which is whitelisted at an external provider. This way, we can just forward mails to a common address instead of adding the whitelisted address to every client.

Features

  • ✅ Monitors an IMAP mailbox for new unread emails
  • ✅ Forwards emails via SMTP with full content preservation (text, HTML, attachments) but replaces the "from" header
  • ✅ Deletes successfully forwarded emails from the source mailbox

Prerequisites

  • Node.js (version 22 or higher)
  • Access to both source and destination email accounts
  • IMAP and SMTP server credentials

Installation

  1. Clone or download this repository
  2. Install dependencies:
    npm install
  3. Copy the environment configuration:
    cp .env.example .env
  4. Configure your email settings in .env

Configuration

Create a .env file in the project root with the following variables:

# Source IMAP Settings (where emails are received)
IMAP_HOST=your-imap-server.com
IMAP_PORT=993
IMAP_USER[email protected]
IMAP_PASSWORD=your-password

# Destination SMTP Settings (where emails are forwarded)
SMTP_HOST=your-smtp-server.com
SMTP_PORT=465
SMTP_USER[email protected]
SMTP_PASSWORD=your-password

# Forwarding Configuration
FORWARD_TO[email protected]
FORWARD_FROM[email protected]

Usage

Run the mail forwarder:

npm start

Or run directly with Node.js:

node --experimental-strip-types src/forward.ts

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published