Skip to content

Latest commit

 

History

History
275 lines (219 loc) · 12.9 KB

README.md

File metadata and controls

275 lines (219 loc) · 12.9 KB

Simple Mail Forwarder(SMF) Circle CI

Gitter Docker Puuls Docker Stars Docker Repository on Quay.io

dockeri.co

Simplest and Smallest Email Forward Service based on Docker.

  1. Config by one line
  2. Run as docker start
  3. Image Size 10MB

View on Github - https://github.com/zixia/docker-simple-mail-forwarder

Voice from Users

@Brian Christner : After testing a ton of different mail projects I finally discovered Simple Mail Forwarder (SMF) by Zixia. This image is based on Alpine which is already a positive. It is super tiny and as the name suggests, easy to use. link

@kachkaev : really happy to discover it! link

@kiani: have a working mail server, seriously, it was that easy. link

@counterbeing : great image. Wonderfully easy interface, with all that i need. 👍 link

@nelfer : Guess what? Your image already supports this! link

What is SMF? (Simple Mail Forwarder)

If you had a domain name and only wanted to have one(or a few) email address from this domain, but you want to forward all the emails to another email account. SMF is exactly what you need. (with Docker)

This docker was built for ultimate simplicity because of this reason. I owned many domains and needed email addresses of them(for fun/work), and I hated to config email server. Some DNS providers provide free email forwarding service for their own domain, some do not. And almose all email forwarding service is NOT free. So I decided to make it myself(thanks docker).

Related Services

I was willing to pay $10/year, but the cheapest plan I could find was $9 per month. Having a $10 USD machine with unlimited mail&domains per month is an amazing idea! And of couse you could also put other dockers on this same machine. :-D

Quick Start (TL;DR)

Just set SMF_CONFIG and run:

$ export SMF_CONFIG='[email protected]:[email protected]:test'
$ docker run  -e SMF_CONFIG="$SMF_CONFIG" -p 25:25 zixia/simple-mail-forwarder

Don't forget to modify the DNS MX record of your domain. (in this example, it's testo.com)

This will forward all emails received by [email protected] to [email protected].

If you want to forward all emails sent to domain testo.com to [email protected], set it like so:

$ export SMF_CONFIG='@testo.com:[email protected]'

See? There is nothing easier.

Quick Test

Tested by BATS(Bash Automated Testing System), a bash implementation of TAP(Test Anything Protol).

How to run:

$ docker run zixia/simple-mail-forwarder test
>> exec bats test
1..20
ok 1 confirm hostname pretend to work.
ok 2 confirm hwclock pretend to work.
ok 3 service postfix could start/stop right.
ok 4 SMF_CONFIG exist
ok 5 SMF_DOMAIN exist
ok 6 virtual maping source is set
ok 7 virtual maping data is set
ok 8 virtual maping db is set
ok 9 system hostname FQDN resolvable
ok 10 postfix myhostname FQDN & resolvable
ok 11 check other hostname setting
ok 12 confirm postfix is running
ok 13 confirm port 25 is open
ok 14 crond is running
ok 15 ESMTP STATTLS supported
ok 16 ESMTP AUTH supported
ok 17 ESMTP STARTTLS supported
ok 18 create user [email protected] by password test
ok 19 ESMTP AUTH by [email protected]/test
ok 20 ESMTP TLS AUTH by [email protected]/test

You are all set! :-]

Environment Variable and Default Values

SMF_CONFIG: MUST be defined. no default setting. (set me! I'm the only parameter~)

SMF_CONFIG Examples

Here's how to config the only environment parameter of SMF Docker:

1. Basic

Forward all emails received by [email protected] to [email protected]:

Forward all emails received by any email address in domain testo.com to [email protected]:

$ export SMF_CONFIG='@testo.com:[email protected]'

You could get the ESMTP AUTH password for you on your docker log. It's randomly generated if you do not provide one.

2. Advanced

Add ESMTP AUTH password:

$ export SMF_CONFIG='[email protected]:[email protected]:ThisIsPassword'

Password will be printed on the docker log.

3. Hardcore

Add as many email accounts as you want, with or without password. Seperated by semicolon or a new line:

$ export SMF_CONFIG='[email protected]:[email protected]:ThisIsPassword;[email protected]:[email protected]:AnotherPassword'

Tips: if you only provide the first password and leave the rest blank, then the passwords for all the rest accounts will be the same as the last password value you set. This is by design.

You can also forward all emails received by [email protected] to multiple destination addresses:

TLS (SSL) Certificates

SMF creates its own certificate and private key when starts. However, this certificate is self signed and so some systems might give you a warning about the server not being trusted. If you have valid certificates for the domain name of the host, then you can use them and avoid the warning about not being trusted.

  1. First you need to prepare the certificate files. Copy your full chain certificate to a file named smtp.cert. Then copy the private key to a file named smtp.key

  2. Copy these files to a folder. For example: /data/certs/. This folder will be mounted as a volume in SMF

  3. When creating the container, add the -v (volume) parameter to mount it to the folder /etc/postfix/cert/ like so:

$ docker run  -e SMF_CONFIG="$SMF_CONFIG" -p 25:25 -v /data/certs/:/etc/postfix/cert/ zixia/simple-mail-forwarder
  1. Your emails should now be forwarded with trusted encryption. You can use this tool to test it: http://checktls.com/

If you do not have a certificate and don't have the $$ to buy one, you can use https://letsencrypt.org if you have shell access to the server (Notice, SMF does not provide, yet, this service). Letsencrypt allows you to create valid trusted certificates for a server, if the server responds to the domain you specify. In order to do this, you need to run the program from within the server and have administrator rights.

  1. First install letsencrypt. This might vary by distribution, but in Ubuntu it is like this:
$ sudo apt-get install letsencrypt
  1. Stop any web server that might be using port 80 (Apache, nginx, etc)

  2. Determine all of the domains and subdomains that you want the certificate to cover, for example mydomain.com, www.mydomain.com, smtp.mydomain.com, etc. Remember to include the domain that SMF will respond to (as per MX record in DNS configuration of the domain)

  3. Execute the following command (you can add as many domains as you wish with the -d option. But remember, their DNS resolution must resolve to the server where letsencrypt is being executed)

$ letsencrypt certonly --standalone -d yourdomain.com -d www.yourdomain.com -d mail.yourdomain.com
  1. Follow the prompts and if everything is successful you will get your certificates in a folder like /etc/letsencrypt/live/mydomain.com

  2. You can now use those certificates to make SMF TLS trusted.

This was a quick way of how to use letsencrypt. For a full tutorial based on your OS see: https://certbot.eff.org/

Helper Scripts

  1. Build from source.
$ ./script/build.sh latest
  1. Run a self-test for SMF docker.
$ ./script/run.sh latest test
  1. Get a shell inside SMF docker.
$ ./script/devshell.sh latest

Manual Test

$ telnet 127.0.0.1 25
> 220 testo.com ESMTP
ehlo test.com
> 250-testo.com
> 250-STARTTLS
> 250-AUTH PLAIN LOGIN
auth plain
> 334
dGVzdGlAdGVzdG8uY29tAHRlc3RpQHRlc3RvLmNvbQB0ZXN0
> 235 2.7.0 Authentication successful
quit
> 221 2.0.0 Bye
> Connection closed by foreign host

P.S. The magic string dGVzdGlAdGVzdG8uY29tAHRlc3RpQHRlc3RvLmNvbQB0ZXN0 stands for [email protected]\[email protected]\0test in base64 encoding, required by AUTH PLAIN.

Useful article about SMTP Authentication: http://www.fehcom.de/qmail/smtpauth.html

Bug

Github Issue - https://github.com/zixia/docker-simple-mail-forwarder/issues

Changelog

master

  • TBD

v0.4.2 (25th Sep 2016)

  • close issue #1
  • increace message size limit from 10MB to 40MB
  • merged pull request from @kminek : allow multiple forwards seperated by "|" #7
  • fix domain name in scripts
  • fix unit test fail error: do not upgrade alpine
  • restore deploy button in reamde: it is docker cloud now.(former tutum)

v0.4.0

  1. manage postfix service by S6
  2. solve PID 1 Zombie Problem
  3. enhanced busybox shell
  • NOT to use OpenRC(very buggy run inside docker container) any more!
  • better ESMTP TLS AUTH test script
  • docker image size: 10MB

v0.3.0 <- Don't use me, I'm BUGGY

  • CI(continuous integration) supported by use CircleCI
  • CD(continuous delivery) supported by use Tutum Button
  • write better tests
  • tune OpenRC inside alpine linux
  • full description README
  • docker image size: 7MB

v0.2.0 <- Don't use me, I'm BUGGY

  • supported specify user password
  • supported ESMTP TLS
  • docker image size: 7MB

v0.1.0

  • dockerized
  • basic forward function
  • self-testing
  • docker image size: 6MB

Cloud Requirement

  • A Cloud Service that could host docker is required.
  • A Docker management platform is recommanded.
    • Docker Cloud(Former Tutum) Deploy to Docker Cloud
  • Docker is required.
    • Docker.com

Author

Zhuohuan LI [email protected] (http://linkedin.com/in/zixia)

profile for zixia at Stack Overflow, Q&A for professional and enthusiast programmers

Copyright & License

  • Code & Documentation 2015© zixia
  • Code released under the Apache 2.0 license
  • Docs released under Creative Commons