Recent Post

Categories

Archives

Cow Computing

10 Jan 22

Simple Mail Server Setup on Ubuntu (Step By Step Guide)

Often you will have to setup a mail server especially when you own a web server or VPS, however, this task is dauntingly hard, since mail is an old product. So, here I would like to jot down a step by step guide to walk through the setup of a simple mail server. By the end of this article, a working IMAP/POP3 server will be up. Nonetheless, if any extra stuff (e.g. the use of spam filter or so) is needed, they can be installed on top later.

First, we have to install “postfix” as the MTA and “mailx” as the mail utility.

sudo apt-get install postfix
sudo apt-get install mailx

Then, we will create a user on ubuntu as the mail user account

sudo useradd -m -s /bin/bash <username>
sudo passwd <username>

Now, the first step is done, and we might have a test on it by issuing

netcat localhost 25

and it should prompt you with this

220 localhost ESMTP Postfix (Ubuntu)

Next, we shall setup the “Maildir” mailboxes for the sake of scalability, this is preferred over the “mbox” mailbox

sudo postconf -e "home_mailbox = Maildir/"
sudo postconf -e "mailbox_command = "

## restart the postfix
sudo /etc/init.d/postfix restart

Now, the setup of postfix is done, and we should move to MDA, and here I have chosen to use “Dovecot” since this is the first MDA I tried and i am used to it. (*note: this install both IMAP and POP3, and you might only install either one of them in case)

sudo apt-get install dovecot-imapd dovecot-pop3d

Open up /etc/dovecot/dovecot.conf, and make sure the following setting is made

protocols = pop3 pop3s imap imaps
pop3_uidl_format = %08Xu%08Xv

## to allow remote access
listen = *

## only set it to no, if the server is to be used with virtual account or internally, else ignore this setting
disable_plaintext_auth = no

mail_location = maildir:/home/%u/Maildir

Then start up the dovecot

/etc/init.d/dovecot start

Up to this moment, the mail server is ready, however if you need SSL support and thunderbird support, read the rest.
To be able to make use of SSL, you need to generate a key and certificate through openSSL, and can be referred to this previous article.
After the key and certificate is ready, set it as follow inside the /etc/dovecot/dovecot.conf

ssl_cert_file = /etc/ssl/certs/<certificate file>.crt
ssl_key_file = /etc/ssl/private/<key file>.key
ssl_disable = no

Finally, to allow thunderbird client to connect to the mail server, modify /etc/dovecot/dovecot.conf as follows:

protocol imap {
...
login_greeting_capability = yes
imap_client_workarounds = tb-extra-mailbox-sep
}

Reference: Postfix How-To Dovecot

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • Twitter

No Comments »

No comments yet.

Leave a comment