https://github.com/deysuman/smtp-listener
A NodeJS script that acts as a SMTP listen server. Accepts all emails, and emits them both as an EventEmitter and through a socket.
https://github.com/deysuman/smtp-listener
listener mail nodejs smtp smtp-client smtp-library smtp-listerner smtp-mail smtp-server socket socket-programming
Last synced: about 2 months ago
JSON representation
A NodeJS script that acts as a SMTP listen server. Accepts all emails, and emits them both as an EventEmitter and through a socket.
- Host: GitHub
- URL: https://github.com/deysuman/smtp-listener
- Owner: deysuman
- License: apache-2.0
- Created: 2018-10-20T17:10:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-20T17:16:35.000Z (over 7 years ago)
- Last Synced: 2025-01-11T04:42:53.862Z (over 1 year ago)
- Topics: listener, mail, nodejs, smtp, smtp-client, smtp-library, smtp-listerner, smtp-mail, smtp-server, socket, socket-programming
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# smtp-listener
A NodeJS script that acts as a SMTP listen server. Accepts all emails, and emits them both as an EventEmitter and through a socket.
[](https://nodejs.org)
## Usage (single access)
If only 1 script needs to receive mails:
```javascript
const SMTPServer = require("smtp-listener").Server;
const server = new SMTPServer(25 /* port */);
server.on("test@example.com", (mail)=>{
...
});
```
## Usage (multi access)
If multiple scripts need to receive mails, create a symlink at `/var/dev/smtp-listener/` pointing to the working directory, then create a symlink at `/etc/systemd/system/smtp-listener.service` pointing to `./service/smtp-listener.service`. Finally run `sudo systemctl start smtp-listener`. This starts the server and keeps it running should it crash.
If you aren't running systemd, do the equivalent on your system.
Then in your scripts do
```javascript
const SMTPClient = require("smtp-listener");
const client = new SMTPClient();
client.on("test@example.com", ()=>{
...
});
```
## Mail object
All listeners receive a single response, a `Mail` object. This is simply the email parsed by [Nodemailer's Mailparser](https://nodemailer.com/extras/mailparser/). See their documentation for details.
## Socket
If you need access to mails from non-JS code (or you don't want to use `SMTPClient`), you can instead listen to the UNIX/Windows socket (default UNIX location: `/tmp/app.smtp-listener`).
The server emits emails as UTF8-encoded JSON to all clients, using [`node-ipc`](https://github.com/RIAEvangelist/node-ipc).