Home
Name Modified Size InfoDownloads / Week
readme.md 2021-11-18 12.6 kB
Totals: 1 Item   12.6 kB 0

Multiple Domain MX Server

There are many free and paid email hosting providers. The Multiple Domain MX Server offers a free solution to self-host your mail server with an easier setup. Reasons to host your own mail server: you may want to provide an email address to your customers using your own domain; sending registration details from a matching domain;

You do not want to use your private email server to send unsolicitated email, or your email server domain could get blocked very quickly. Recommend to use a service like Sendgrid for unsolicited email marketing.

Attachments are supported. A view source for viewing the original email envelope is available

Installation

You will need to download the appropriate executable and the settings.json.

Download

The files include,

The server executable,

mxserver.exe        for Windows
mxserver-linux      for Ubuntu/Debian 
mxserver-macos      for MacOSX

The desktop email client,

mailer Setup X.X.X.exe  for Windows
mailer_linux_X.X.X.deb  for Ubuntu/Debian
mailer_X.X.X.dmg        for MacOSX

The server configuration,

settings.json       for all

WordPress plugin for reading and sending email using template from W3SCHOOLS.COM at https://www.w3schools.com/w3css/tryw3css_examples_mail.htm, see source repository at https://github.com/pingleware/mail-reader

pingleware-mail-reader.zip

Postman

Multiple Domain MX Server.postman_collection

Configuring SETTINGS.JSON

If you are using your home or business to host your own mail server, you need to obtain the hostname for the IP that your ISP has assigned. This is also known as the public hostname. You can obtain your public hostname by navigating your browser to https://www.whoismyisp.org and choose Hostname, then copy the hostname to the settings.json file.

You need to obtain your local IP which can be obtain by issuing the command ipconfig or ifconfig, and copy you local IP address to the host parameter in settings.json

You then need to set an arbitrary port. The host and port is for the REST server which is used for sending emails. Receiving emails using the node-mailin module with the port configured by the smtp.port value in SETTINGS.JSON.

Since all emails both sent and received are stored in a MySQL table, you need to have access to a MySQL table that is publicly accessible. A good choice for a MySQL hosting is https://www.freesqldatabase.com/ which offers a free or a paid version. The paid version is annual subscription and as of this date is $21 per year and gives you 100 MB storage.

Once you have have a MySQL host, you need to create a database and associated table and execute the create statement on the new table, then copy the host IP address, database name, user and password to the settings.json.

Next you will need to specifiy the domains that will be permitted to use the mail server. Just replace the [TLD] setting with the actual domain name. You need to obtain DNS keys and to useful tool is located at https://dkimcore.org/tools/. You will need this information for setting your DNS keys for your new mail server so your mail server can be found?

{
    "hostname": "[see https://www.whoismyisp.org/]",
    "host": "[local IP]",
    "port": 3030,
    "smtp": {
        "port": 587,
        "username": "[SMTP Authentication User]",
        "password": "[SMTP Authentication Password]",
        "privateKey": "[SMTP private key filename]",
        "certificate": "[SMTP certificate filename]"   
    },
    "mysql": {
        "host": "[MySQL Server IP or hostname]",
        "user": "[MySQL User for database specified in name]",
        "pass": "[MySQL Password for above User]",
        "name": "[MySQL Database name]",
        "queries": {
            "create": {
                    "messages": "CREATE TABLE `messages` (
                        `id` int(11) NOT NULL,
                        `domain` varchar(255) NOT NULL,
                        `location` enum('inbox','outbox','sent','trash') NOT NULL DEFAULT 'inbox',
                        `sender` varchar(255) NOT NULL,
                        `recipient` varchar(255) NOT NULL,
                        `date` varchar(255) NOT NULL,
                        `subject` varchar(255) NOT NULL,
                        `content` longtext NOT NULL,
                        `envelope` longtext
                        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
                },
                {
                    "users": "CREATE TABLE `users` (
                        `id` int(11) NOT NULL,
                        `user_name` varchar(255) NOT NULL,
                        `user_email` varchar(255) NOT NULL,
                        `password` varchar(255) NOT NULL,
                        `first_name` varchar(255) NOT NULL,
                        `last_name` varchar(255) NOT NULL,
                        `display_name` varchar(255) NOT NULL,
                        `domains` longtext NOT NULL
                        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
                }
        }
    },
    "domains": {
        "[TLD]": {
            "dkim": {
                "domainKey": "[TLD]",
                "keySelector": "[see https://dkimcore.org/tools/]",
                "publicKey": "[see https://dkimcore.org/tools/]",
                "privateKey": "[see https://dkimcore.org/tools/]",
                "bind9": "[see https://dkimcore.org/tools/]",
                "tinyDNS": "[see https://dkimcore.org/tools/]"
            },
            "user_role": "[A user role propagated from your WordPress website]",
            "user_validation_url": "[The WP_JSON URL from the pingleware-mail-client WordPress plugin]"
        },
        ...
    }
}

Once your SETTINGS.JSON is configured, you can start the executable within the same directory. You then have to configure your DNS keys.

Open SMTP Port (optional?)

If you are using a router or firewall, you will need to open the SMTP port for router and firewall to pass requests to your mail server.

Configuring your DNS keys

You must configure your DNS keys for each domain your want to use with the mail server.

Adding MX records to Cloudflare

Configure as a Service

Ubuntu

Download the mxserver-server.sh, mxserver.service and mxserver.sh files, and place in the following paths

mxserver.service    => /etc/systemd/system
mxserver-server     => /root/mxserver-multiple-domain

change the permissions to executable using

sudo chmod +x /etc/systemd/system/mxserver.service

We must now reload the list of services,

sudo systemctl daemon reload

Then activate the launch of the service at boot,

sudo systemctl enable mxserver.service

To start the service,

sudo systemctl start mxserver.service

Windows

Referencing https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/may/windows-powershell-writing-windows-services-in-powershell

MacOS

Why another mail client?

The current mail clients only support a single email at a time and you must manually configure the mail client for each additional email/domain to be supported. This would make your mail client navigation very cluttered. The Multiple Domain Mail client is designed around the Multiple Domain MX Server multiple domains. Additionally, the Multiple Domain MX Server does not use permit reading emailing through the traditional SMTP that existing email clients use due to the fact the module node-mailin is for incoming messages only. A custom email client is warranted.

During development, I have been testing live and I have noticed there have been hack attempts to spoof and read email through the SMTP service, and these attempts have resulted in failure for the attacker which is a pleasant discovery.

Additionally, the Administrator Assistant application at https://sourceforge.net/p/administrative-assistant/ to include integration with autonomous operations, so you will not have to continually check emails.

Release Schedule

Whenever the code base is updated, a new standalone executable is created and replaced with the existing executable.

Version         Date            Changes
1.0.0           ??/??/202?      Initial release
Spam Assassin for Windows - https://www.jam-software.com/spamassassin

FAQs

Multiple Domain MX Server uses node-mailin SMTP to accept incoming mail. Node-mailin does not permit reading email by a mail client and throw a warnning exception when a read command is send by a mail client. Additionally, node-mailin deletes each message saved in the ./mailbox directory after each session. This make Multiple Domain MX Server safe from unauthroized email access. Email are instead saved in a MySQL table. If only HRC had similar security on her email server, could breaches have been prevented?

Muiltiple Domain MX Server uses node-mailin SMTP to accept incoming mail, thus preventing a third party from using SMTP to spoof and send unauthorized email. The Send API will accept send requests by a user-specified domain list.

When testing the API using POSTMAN, I notice POSTMAN will create a different B64 hash using the same credentials, on startup the Multiple Domain MX Server will create an auth.txt file that contains the Authentication hash based on the credentials set in the SETTINGS.JSON file. When using POSTMAN, deselect Authentication and manually set an the header Authroization to the value contained in the auth.txt file.

Advanced Topic - Multiple Domain MX Server

Using apache mod_proxy, you can configure Multiple Domain MX Server to be invoked from an apache URL, even as a secured connection. The following steps show you how to configure apache.

Step 1: Setup Apache for PROXY

his step will allow the use of valid SSL session from apache and proxy the request to a backend node process.

First enable mod_proxy,

a2enmod proxy

then restart apache,

service apache2 restart

Edit the apache.conf, and place the following after </Directory> tag

ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
    Require all granted
</Proxy>

<Location /mxserver.app>
    ProxyPass http://localhost:3030
    ProxyPassReverse http://localhost:3030
</Location>

then restart apache,

service apache2 restart

Step 2: Create a service process

Create a new file located in /etc/systemd/system/

nano /etc/systemd/system/mmxserver.service

Then copy the contents,

[Unit]
Description=Multiple Domain MX Server
AFtert=network.target
StartLimitIntervalSec=0
#
[Service]
Type=simple
User=root
Restart=always
RestartSec=1
WorkingDirectory=/root/mxserver-multiple-domain
ExecStart=/root/mxserver-multiple-domain/mxserver-linux
#
[Install]
WantedBy=multi-user.target

then enable the new service,

systemctl enable mxserver.service

Step 3: Upload the files to the /root path

You will need to upload these two files to /root path,

mxserver-linux
settings.json

Also change the permissions on the file mxserver-linux to be executable,

chmod +x mxserver-linux

Step 4: Start the Service

To start the service,

systemctl start mxserver.service

Step 5: Access the Multiple Domain MX Server from Apache

Use the URL,

http://localhost/mxserver.app/

or

https://localhost/mxserver.app/

if you have SSL enabled?

EOL or End-of-Life

When a piece of software is useful, there should never be an EOL doctrine. The intention for this application is to achieve immoratlity ;).

At some point of time in the future, this project may appear to be dead and abandon. The opposite will be true!

When this project reaches that stage, this project has matured to a level where maintenance is minimal (mostly updating to latest version of Node).

Patrick Ingle
Developer
November 7, 2021
Source: readme.md, updated 2021-11-18