Simple Mail Server setup with Docker

Tram Ho

Preamble

Sending emails is a feature that almost every web project has, usually we will use popular email services like gmail, sendgrid, … or in Ruby on Rails, there are gem support. Emailing tests like letter_opener_web, … is also quite simple to set up and use.

But using the above methods has certain disadvantages, for example, when using gmail or sendgrid, you must use real email, assuming you have a spam test email, but the recipient email must also be Real email can be used, you can also use email for 10 minutes to receive the email, but each test has to update the email to the database with rice, a bit cumbersome =)) If using gem, it is also ok, but it doesn’t seem to catch exceptions like not authen, errors server or smtp or something: v

Or your project is about managing, sending and receiving emails, the above methods do not seem feasible in the development process, so why not build a mail server on your computer? email accounts, you can use any domain, smtp, imap, pop3 support, do not worry about creating incidents related to email (well, the mail server I am about to show below it can also forward emails out) outside, I have not yet tried to turn off, so maybe the fastest is … off the network to run local) and the whole team can share in the LAN, or deploy to a certain vps and then use.

Structure of a mail server

A basic mail server will have the following structure:

  • Postfix (MTA): This is an SMTP server, in charge of sending and forwarding email, there are many types of SMTP servers but Postfix is ​​a free map that is also quite good, so many people choose.
  • Dovecot (LDA): this is a POP3 / IMAP server, used for reading email, also common when using free like Postfix, Dovecot will access where Postfix stores emails to read emails =)))
  • Roundcube Web Interface: is the interface to manage, read and send email in the browser, similar to email manager of google or yahoo (actually it is much simpler)
  • Mailserver-admin: manage email accounts, domain, …

I’ll introduce just a little bit, now let’s move on to the main part

Install Mail Server

I also read quite a lot of articles on how to setup mail server, but because I was afraid of installing with configuration, I searched for docker projects, and luckily found a project that I feel was quite good, considered a complete mail server just turn on up and use it. You can download it here

The way to run is quite simple:

  1. Clone project, then point to the folder containing the project
  2. Create .env file then copy the content of the file .env.dist through and edit a few things, below I edit the following

  1. Run bin/production.sh pull to pull the necessary docker image
  2. Run bin/production.sh up -d to create a container and run in the background, if you want to turn off, run bin/production stop , and if you want to turn it back on, just run bin/production start
  3. When running for the first time, you need to run the command bin/production.sh run --rm web setup.sh to create a root account, use this account to create other emails and configure mail server as domain, .. .
  4. That’s it, use it

Mail server services:

Interface to create and manage email accounts:

Email sending and receiving management interface:

I have used it for a while, I feel quite good, sending email to release the door, the whole team can share =)) but this is only in the development environment, and I have not run on production, so I do not know if feasible. High or not, you guys commented enthusiastically.

Reference: https://github.com/jeboehm/docker-mailserver

Share the news now

Source : Viblo