Postfix, Dovecot, and System User Accounts on Ubuntu 10.04 (Lucid)
Updated by Linode
This guide has been deprecated and is no longer being maintained.
Postfix is a popular mail transfer agent or “MTA”. This document will allow you to create a mail system using Postfix as the core component and aims to provide a simple email solution that uses system user accounts for authentication and mail delivery and Dovecot for remote mailbox access. If you do not need to authenticate to Postfix for SMTP service or use POP or IMAP to download email, you may consider using the Basic Email Gateway with Postfix document to install a more minimal email system. If you plan to host a larger number of domains and email aliases, you may want to consider a more sophisticated hosting solution like the Email Server with Postfix, MySQL and Dovecot.
Set the Hostname
Before you begin installing and configuring the components described in this guide, please make sure you’ve followed our instructions for setting your hostname. Issue the following commands to make sure it is set properly:
hostname hostname -f
The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).
Issue the following commands to install any outstanding package updates:
apt-get update apt-get upgrade
Issue the following commands to install all required software:
apt-get install libsasl2-2 libsasl2-modules sasl2-bin postfix apt-get install dovecot-postfix
During the installation process, the package manager will prompt you for the responses to a few questions to complete the Postfix installation. To the first question regarding the type of mail server you want to configure, select “Internet Site” and continue as in the following image:
The next prompt will ask for the system mail name. This should correspond to the fully qualified domain name (FQDN) that points to your Linode’s IP address. In this example, we’re using a machine specific hostname for our server. Set the reverse DNS for your Linode’s IP address to the fully qualified domain name you assign as the system mail name. You will be able to send mail from additional domains as configured later in this document. See the following example:
/etc/default/saslauthd file to allow the SASL authentication daemon to start. Uncommon or add the following line:
/etc/postfix/sasl/smtpd.conf file, and insert the following line:
Issue the following command to start the SASL daemon for the first time:
SSL or TLS provides a method of encrypting the communication between your remote users and your mail servers. While this does not encrypt your email messages from end to end, it does ensure that your login credentials are transmitted securely and that communications are secure between your client machine and the email server.
Issue the following sequence of commands to install the prerequisites and generate a self-signed SSL certificate:
apt-get install openssl openssl req -new -x509 -sha256 -days 365 -nodes -out /etc/ssl/certs/ssl-mail.pem -keyout /etc/ssl/private/ssl-mail.key
Be sure to generate a certificate with a “Common Name” that corresponds to the host name that your users will connect your mail server (e.g.
Mail clients may have an issue with certificates generated in this manner because they are not signed by a recognized certificate authority. Consider our documentation for generating commercial ssl certificates if you need a commercially verified certificate.
You can use any SSL certificate with Postfix. If you already have a commercial certificate or another SSL certificate for your web server, you can use these
At this point you should be able to send email using your Postfix instance by authenticating with SMTP. Authentication credentials are your system user accounts.
Consider the basic email gateway guide for more information regarding Postfix virtual hosting configuration. If you need to deliver mail locally, continue for documentation of mail routing and the Dovecot POP3/IMAP server.
Configure Mail Delivery
The above Postfix configuration makes it possible to send mail using postfix. If your server receives email, Postfix requires additional configuration to deliver mail locally. Edit the
main.cf file to insert or modify the following configuration directives:
1 2 3
myhostname = lollipop.example.com virtual_alias_maps = hash:/etc/postfix/virtual home_mailbox = mail/
Issue the following command to ensure that new user accounts have a
Every existing user that receives email will also need to make their own
Maildir, by issuing the following command:
/etc/postfix/virtual file to map incoming email addresses to their destinations. Consider the following example:
Here, all mail sent to the three addresses beginning with the characters
username@ are delivered to the local user “username” and deposited to a Maildir in the
/home/username/mail/ directory. The three addresses that begin with the characters
fore@ are delivered to the email address
email@example.com. The final set of three email addresses beginning with
team@ are both delivered locally and sent to the
firstname.lastname@example.org email address.
You can add additional lines in the same format as the above to control how all incoming email is delivered to local or external destinations. Remember that incoming email has no firm relationship to the name of the user account.
/etc/alias file to add the following line. This will to reroute all local mail delivered to the root user to another user account. In the following example, all mail delivered to
root will be delivered to the
username user’s mail box.
When you have configured mail delivery issue the following command to recreate the aliases database, rebuild the virtual alias database, and restart the mail server:
postmap /etc/postfix/virtual /etc/init.d/postfix restart
Dovecot is a contemporary POP3/IMAP server that makes it possible to access and download mail from your mail server remotely onto your local system.
Configure Remote Mail Access
Edit the following configuration directive in the
/etc/dovecot/conf.d/01-dovecot-postfix.conf file to select the services that Dovecot will provide.
protocols = imap imaps pop3 pop3s
protocols directive enables
pop3 services within Dovecot along with their SSL-encrypted alternatives. You may remove any of these services if you do not want Dovecot to provide
pop3 or ssl services.
Edit the following directives in
/etc/dovecot/conf.d/01-dovecot-postfix.conf to ensure that Dovecot can find your user’s Maildirs:
mail_location = maildir:~/mail:LAYOUT=fs
Once configured, issue the following command to restart the Dovecot instance:
You may now access email by configuring a local email client to contact the server you have set up. Authentication credentials are the same as the system user accounts. These accounts can be configured outside of this document at any time.
Organize Mail Services
This document describes a complete email system configuration. How you use and manage your system from this point forward is beyond the scope of this document. At the same time, we do encourage you to give some thought to the organization of your user accounts and email delivery. Keeping a well organized and easy to manage system is crucial for sustainable use of this system.
Organizational structure is crucial in this kind of deployment because delivery of inbound email addresses are configured independently of user accounts. Furthermore, email accounts and user accounts need not correspond or reference each other. This may be confusing for some users. To help resolve this confusion you may want to establish a systematic convention for email addresses and corresponding user accounts to the mail server.
Remember that system user accounts may provide access to other services on the system. Unless this access is specifically prohibited, all system user accounts will have SSH access to the server using the same credentials that are used for logging into the email services.
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This guide is published under a CC BY-ND 4.0 license.