Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ReachFive/fake-smtp-server
Fake SMTP Server for email testing
https://github.com/ReachFive/fake-smtp-server
Last synced: about 1 month ago
JSON representation
Fake SMTP Server for email testing
- Host: GitHub
- URL: https://github.com/ReachFive/fake-smtp-server
- Owner: ReachFive
- License: mit
- Created: 2017-09-18T16:29:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-21T15:24:54.000Z (9 months ago)
- Last Synced: 2024-04-14T07:51:37.927Z (8 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/fake-smtp-server
- Size: 2.14 MB
- Stars: 191
- Watchers: 6
- Forks: 78
- Open Issues: 53
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - ReachFive/fake-smtp-server - Fake SMTP Server for email testing (JavaScript)
README
# Fake SMTP Server
Fake SMTP Server is an email testing tool for QA & development teams.
It allows manual testing in a web interface, and automated testing via an API.## Docker image
[reachfive/fake-smtp-server](https://hub.docker.com/r/reachfive/fake-smtp-server)## API
#### Listing all received emails
Received mails are listed on `http://localhost:1080/api/emails`, and looks like this:
```json
[
{
"attachments": [],
"text": "Hi Bob!",
"textAsHtml": "Hi Bob!
",
"subject": "Hi",
"date": "2017-09-18T16:12:16.000Z",
"to": {
"value": [
{
"address": "[email protected]",
"name": "Bob"
}
],
"html": "Bob <[email protected]>",
"text": "Bob "
},
"from": {
"value": [
{
"address": "[email protected]",
"name": "Joe"
}
],
"html": "Joe <[email protected]>",
"text": "Joe "
},
"messageId": "<1433879119.43.1505751136615@[10.143.108.87]>",
"html": false
}
]
```You can filter emails with the following parameters:
* `from`: filter sender
* `to`: filter recipient
* `since`: filter email date
* `until`: filter email date
Example:```
GET http://localhost:1080/api/[email protected]&[email protected]&since=2017-09-18T12:00:00Z&until=2017-09-19T00:00:00Z
```##### Viewing headers in responses
By default, fake-smtp-server will not capture custom headers in emails. To enable headers, start the server with the `--headers` flag. If enabled, headers will be serialized as an object type.
For reference for what headers look like, consult [Nodemailer's documentation](https://nodemailer.com/extras/mailparser/#headers-map), but keep in mind that the HTTP endpoint returns plain JSON objects rather than `Map`s.
#### Removing all received email
To remove all emails without restarting the server:
```
DELETE http://localhost:1080/api/emails
```## Web interface
Go to `http://localhost:1080`
## Install
```bash
npm install -g fake-smtp-server
```## Usage
```
Usage:
fake-smtp-server [OPTIONS] [ARGS]Options:
-s, --smtp-port [NUMBER] SMTP port to listen on (Default is 1025)
--smtp-ip [IP] IP Address to bind SMTP service to (Default is 0.0.0.0)
-h, --http-port [NUMBER] HTTP port to listen on (Default is 1080)
--http-ip [IP] IP Address to bind HTTP service to (Default is 0.0.0.0)
-w, --whitelist STRING Only accept e-mails from these adresses. Accepts
multiple e-mails comma-separated
-m, --max [NUMBER] Max number of e-mails to keep (Default is 100)
-a, --auth STRING Enable Authentication
--headers Enable headers in responses
-k, --no-color Omit color from output
--debug Show debug information
```## Configure fake-smtp-server to run as a service at startup
These instructions below were tested on **Ubuntu 18.04 LTS** but they should work out of the box (or close to it) on any distribution using ***systemd*** and ***rsyslog***.
### Systemd service
#### Create the `fakesmtp.service` service unit
* `sudo vim /etc/systemd/system/fakesmtp.service` with the following content
```shell
[Unit]
Description=Fake SMTP service
After=network.target
StartLimitIntervalSec=0
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=fake-smtp-server[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/usr/local/bin/fake-smtp-server # You can add extra options and arguments here[Install]
WantedBy=multi-user.target
```#### Make the new service launch on startup
* `sudo systemctl enable fakesmtp.service`#### Start/Stop/Restart the service
* `sudo systemctl start fakesmtp.service`
* `sudo systemctl stop fakesmtp.service`
* `sudo systemctl restart fakesmtp.service`### Logging using rsyslog
The output is recorded by default to `/var/log/syslog` but you can create a separate log file for your service (in this example, logs will be saved to `/var/log/fakesmtp.log`).
#### Create a new **rsyslog** config file
* `sudo vim /etc/rsyslog.d/fakesmtp.conf` with the following content:
```shell
if $programname == 'fake-smtp-server' then /var/log/fakesmtp.log
& stop
```#### Restart **rsyslog** and then restart your shiny new fakesmtp service
* `systemctl restart rsyslog.service`
* `systemctl restart fakesmtp.service`