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.
- ✅ 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
- Node.js (version 22 or higher)
- Access to both source and destination email accounts
- IMAP and SMTP server credentials
- Clone or download this repository
- Install dependencies:
npm install
- Copy the environment configuration:
cp .env.example .env
- Configure your email settings in
.env
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]Run the mail forwarder:
npm startOr run directly with Node.js:
node --experimental-strip-types src/forward.ts