Giter Site home page Giter Site logo

fake-smtp-server's Introduction

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

API

Listing all received emails

Received mails are listed on http://localhost:1080/api/emails, and looks like this:

[
  {
    "attachments": [],
    "text": "Hi Bob!",
    "textAsHtml": "<p>Hi Bob!</p>",
    "subject": "Hi",
    "date": "2017-09-18T16:12:16.000Z",
    "to": {
      "value": [
        {
          "address": "[email protected]",
          "name": "Bob"
        }
      ],
      "html": "<span class=\"mp_address_group\"><span class=\"mp_address_name\">Bob</span> &lt;<a href=\"mailto:[email protected]\" class=\"mp_address_email\">[email protected]</a>&gt;</span>",
      "text": "Bob <[email protected]>"
    },
    "from": {
      "value": [
        {
          "address": "[email protected]",
          "name": "Joe"
        }
      ],
      "html": "<span class=\"mp_address_group\"><span class=\"mp_address_name\">Joe</span> &lt;<a href=\"mailto:[email protected]\" class=\"mp_address_email\">[email protected]</a>&gt;</span>",
      "text": "Joe <[email protected]>"
    },
    "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, but keep in mind that the HTTP endpoint returns plain JSON objects rather than Maps.

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

  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
[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:
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

fake-smtp-server's People

Contributors

alexgalays avatar ameliabradley avatar bioball avatar fiblan avatar jainsahab avatar jcdelmas avatar pioneer32 avatar stephaneetje avatar thyamarkos avatar wadjetz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fake-smtp-server's Issues

Error: Mail command failed: 421 Error: too many unauthenticated commands

Feature request (Bugfix)

Current Behaviour
While sending emails through automated test cases to fake-smtp-server after few successful deliveries it's started throwing an error that Mail command failed: 421 Error: too many unauthenticated commands due to the spam emails filtering condition for unauthenticated users or clients, this is nodemailer configuration option, which is not implemented yet in this package.

Resulting it's not allowing us to send email to the SMTP server, even if we pass the authentication credentials to the configuration it only works for the API calls to fetch the emails but not for SMTP server.

Desired behavior
We can pass one property with fake-smtp-server start command to set nodemailer's maxAllowedUnauthenticatedCommands.

I will create a PR for the proposed fixes.

404 when trying to remove all messages via API

Using Postman I'm sending DELETE http://localhost:1080/api/emails
the response is:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error</title>
    </head>
    <body>
        <pre>Cannot DELETE /api/emails</pre>
    </body>
</html>

Please note GET http://localhost:1080/api/emails works fine

context path for web and api

It would be nice to have an option to expose api and web frontend on a custom path. It would be easier to proxy that way.

lets say option is base-path, the following would expose all api and web on path /devmail
--base-path /devmail

App fails when the field "to" is undefined

When sending an email with adresses int the BCC field but nothing in the TO field, the front-end fails (show blank page) with the following error in console :
react-dom.production.min.js:4408 TypeError: Cannot read property 'value' of undefined

Related to #36 and #19

Usage of option --auth

Hello there.

How is the feature --auth used? What is the syntax?

Documentation says:
-a, --auth STRING Enable Authentication

I can startup with --auth USERNAME:PASSWORD, but what does that mean?

EDIT: This seems to control access to the web interface. I was expecting to be able to use SMTP auth. Is that even possible?

`punycode` module is deprecated

I'm getting the following error when trying to test my .Net 7.0 web application that sends an email, on Windows 10 Pro computer, using version v21.3.0 of node:

>fake-smtp-server --smtp-port 25 --http-port 9888 --max 10
INFO: SMTP server listening on 0.0.0.0:25
(node:29676) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
INFO: HTTP server listening on http://0.0.0.0:9888
ERROR: Uncaught exception: TypeError: Cannot set property errored of #<Readable> which has only a getter
ERROR: Uncaught exception: TypeError: Cannot set property errored of #<Readable> which has only a getter

My unit test fails due to timeout.

Headers aren't properly serialized to JSON

Great module! However, I'm noticing that the headers aren't being properly serialized to JSON.

simpleParser turns the headers into a Map object, and when Map's are JSON-stringified, they get serialized as "{}", regardless of whether there's data in the map or not. There should be some extra logic that deals with how to serialize these.

This link should be helpful:
http://2ality.com/2015/08/es6-map-json.html

Http server does not respond

I'm strarting your excellent tool using no particular options

$ fake-smtp-server
INFO: SMTP server listening on 0.0.0.0:1025
INFO: HTTP server listening on http://0.0.0.0:1080

I am doing this on a Debian 10 virtual machine.

I am actually able to send email using this fake smtp server from outside the VM.

Great !

But ... I cannot open web gui and I have no idea why.

I already checked that port 1080 is not blocked.

~$ sudo ufw status numbered | grep 1080
[18] 1080                       ALLOW IN    Anywhere
[33] 1080 (v6)                  ALLOW IN    Anywhere (v6)

I laso tried to access web gui using vm local ip, and also tried starting fake-smtp-server using the local ip of the machine as http-ip, but nothing changes, http server doesn't reply.

$ fake-smtp-server --http-ip 192.168.229.128
INFO: SMTP server listening on 0.0.0.0:1025
INFO: HTTP server listening on http://192.168.229.128:1080

From inside VM, using the ip is reachable

$ curl 192.168.229.128:1080
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><title>Fake SMTP Server</title><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"></head><body><div id="root"></div><script type="text/javascript" src="./static/js/main.673a0db7.js"></script></body></html>

From outside opening chrome at "http://192.168.229.128:1080/" give no reply

Could you suggest me what can I check to diagnose?

Empty web interface

Hi,

The web UI do not render emails stored. (Just a blank page with only Email written)
The web view filtered by address return a 404 :(.
I can retrieve them using the rest interface.

Otherwise, this app is great and really simple to install :)
I looked the code, but am not familiar with node, so I did not really understand where the emails are lost.

Running on node v8.6.0

Web interface shows no emails

Hi,
after sending the first email, the web interface stops working:

TypeError: Cannot read property 'value' of undefined
    at N (App.js:23)
    at Zi (react-dom.production.min.js:3273)
    at Ra (react-dom.production.min.js:3899)
    at Bo (react-dom.production.min.js:5514)
    at $o (react-dom.production.min.js:5536)
    at Pl (react-dom.production.min.js:5958)
    at Ol (react-dom.production.min.js:5925)
    at xl (react-dom.production.min.js:5860)
    at Ko (react-dom.production.min.js:5787)
    at Object.enqueueSetState (react-dom.production.min.js:2789)
App.js:23 Uncaught (in promise) TypeError: Cannot read property 'value' of undefined
    at N (App.js:23)
    at Zi (react-dom.production.min.js:3273)
    at Ra (react-dom.production.min.js:3899)
    at Bo (react-dom.production.min.js:5514)
    at $o (react-dom.production.min.js:5536)
    at Pl (react-dom.production.min.js:5958)
    at Ol (react-dom.production.min.js:5925)
    at xl (react-dom.production.min.js:5860)
    at Ko (react-dom.production.min.js:5787)
    at Object.enqueueSetState (react-dom.production.min.js:2789)

Messages are still visibile via the api:

$ curl --silent http://localhost:1080/api/emails | jq
[
  {
    "attachments": [],
    "headerLines": [
      {
        "key": "subject",
        "line": "Subject: bla bla"
      },
      {
        "key": "",
        "line": "Hello,"
      },
      {
        "key": "",
        "line": "bla bla bla"
      }
    ],
    "subject": "bla bla",
    "html": false
  }
]

Web interface - clicking an email can toggle all other emails

Hi there.

Thanks for this project.

According to RFC 2822:

Though optional, every message SHOULD have a "Message-ID:" field.

I appreciate this is an uncommon scenario, but if incoming emails don't have the Message-ID field then the email toggling can get screwed up in the web interface.

The toggle code in App.js looks like this:

handleToggle = email => () => {
    if (this.state.activeEmail === email.messageId) {
        this.setState({ activeEmail: null });
    } else {
        this.setState({ activeEmail: email.messageId });
    }
};

Without a message ID, the this.state.activeEmail === email.messageId check becomes null === undefined, which of course falls to the else block and sets activeEmail to undefined.

Once that's happened, the isOpen attribute of the Email component becomes true for any email that has no messageId property:

{hasEmails && this.state.emails.map(email => (
    <Email email={email}
        isOpen={this.state.activeEmail === email.messageId} // i.e. undefined === undefined
        onToggle={this.handleToggle(email)}
        key={email.messageId} />
    ))
}

I haven't tested, but presumably state.activeEmail could be changed to something like activeIndex and make use of the map index.

Node 18.12.0 Support: Upgrading mailparser to 3.6.3

I'm getting the following error:

Exception has occurred: TypeError: Cannot set property errored of #<Readable> which has only a getter
  at new MessageSplitter (/<REDACTED>/node_modules/mailsplit/lib/message-splitter.js:28:22)
    at new MailParser (/<REDACTED>/node_modules/mailparser/lib/mail-parser.js:132:25)
    at module.exports (/<REDACTED>/node_modules/mailparser/lib/simple-parser.js:25:18)
    at parseEmail (/<REDACTED>/node_modules/fake-smtp-server/index.js:81:10)
    at SMTPServer.onData (/<REDACTED>/node_modules/fake-smtp-server/index.js:54:5)
    at SMTPConnection.handler_DATA (/<REDACTED>/node_modules/smtp-server/lib/smtp-connection.js:1307:22)
    at SMTPConnection._onCommand (/<REDACTED>/node_modules/smtp-server/lib/smtp-connection.js:497:17)
    at SMTPConnection._parser.oncommand (/<REDACTED>/node_modules/smtp-server/lib/smtp-connection.js:58:52)
    at readLine (/<REDACTED>/node_modules/smtp-server/lib/smtp-stream.js:128:22)
    at SMTPStream._write (/<REDACTED>/node_modules/smtp-server/lib/smtp-stream.js:132:13)

Which was solved with the new version of mailparser

How to bind the server to 0.0.0.0?

I've run the server and I'm not able to connect to the server from other servers since the server is bound to 127.0.0.1:<port_number>.

Can't see Attachments in UI

It would be nice to have a link to the attachments as well in the UI. Currently this is only accessible through the API.

CC in Web Interface

It would be nice to have a CC field below To in the web interface, so we don't have to dig into the API

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.