How to install a mail server (postfix) supporting IMAP and POP3 (Ubuntu)

Step 1 – Create

Add an MX record to your DNS using the following parameters:

  • Hostnamemail
  • Priority10


Step 2 – Install and configure postfix

Don’t enter anything during the installation.  In the next step we will be configuring postfix more precisely, and any configuration set now will be overwritten.


Reference my configuration if you aren’t sure what to enter:

  • General type of mail configurationInternet site
  • System mail
  • Root and postmaster recipient: notblog  (Your sudo-privileged account, not root)
  • Other destinations to accept mail forlocalhost,,
  • Force synchronous updates on mail queue?No
  • Local networks: [::ffff:]/104 [::1]/128
  • Mailbox size limit
  • Local address extension character+
  • Internet protocols to useall


Step 3 – Change spool format to Maildir


Step 4 – Install IMAP and POP3 support

Answer No when asked about setting up a web interface.  There are much better alternatives to using courier for web mail.  I recommend roundcube.  Check back soon for a guide on using web mail.


Step 5 – Add aliases for multiple domains and mail accounts

This step is optional.  Following it will allow you to:

  • Handle mail for multiple domains with a single mail server.
  • Forward multiple mailboxes (webmaster, sysadmin, etc.) to a single mailbox.


  •  Line 1: Enter the domain name this mail server will be used for as well as any other domains hosted on this machine.  This will allow you to configure all of the domains to send mail to a single account.  Separate the domains with spaces.  If you aren’t using any other domains, enter the main domain only.
  • Line 2: This points postfix to the alias map at  /etc/postfix/virtual which we will be creating in the next step.  This file will describe where to forward mail sent to certain domains and/or mailboxes.


Write the following to /etc/postfix/virtual, adding domains and mailboxes you’d like to be forwarded:


Then run  postmap to optimize the alias map.  Postfix will read the file much more quickly if this step is taken.


Step 6 – Install dovecot


Step 7 – Restart postfix

8 thoughts on “How to install a mail server (postfix) supporting IMAP and POP3 (Ubuntu)”

  1. And thats it?? No how to check and send emails?? Most people who will come across this will need a COMPLETE description.

  2. Thanks for the post, this filled in the gaps for what I needed.

    The above comments are pretty annoying, if you need that much hand-holding you should not be configuring servers.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.