This brief tutorial shows students and new users how to install and configure the Postfix mail server on Ubuntu 18.04 | 16.04 servers.
For the uninitiated, Postfix is an open-source and free mail transfer agent that routes and delivers emails. It focuses on security and can be installed on most Linux systems, including Ubuntu using a simple command.
For students and new users looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.
Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.
To get started follow the steps below:
Install Postfix on Ubuntu
Postfix packages are available via Ubuntu default repositories. Using a simple command, you’ll be able to install it in no time.
To get Postfix installed, run the commands below:
sudo apt update sudo apt install postfix
When prompted whether to accept the packages that will be downloaded and installed, type y for Yes.
During the installation, you’ll be prompted to choose Postfix configuration settings by selecting its configuration site and the mail system name or domain name.
Package configuration ┌───────────────────────────┤ Postfix Configuration ├───────────────────────────┐ │ Please select the mail server configuration type that best meets your needs. │ │ │ │ No configuration: │ │ Should be chosen to leave the current configuration unchanged. │ │ Internet site: │ │ Mail is sent and received directly using SMTP. │ │ Internet with smarthost: │ │ Mail is received directly using SMTP or by running a utility such │ │ as fetchmail. Outgoing mail is sent using a smarthost. │ │ Satellite system: │ │ All mail is sent to another machine, called a 'smarthost', for delivery. │ │ Local only: │ │ The only delivered mail is the mail for local users. There is no network. │ │ │ │ General type of mail configuration: │ │ │ │ No configuration │ │ Internet Site │ │ Internet with smarthost │ │ Satellite system │ │ Local only │ │ │ │ <Ok> <Cancel> │ │ │ └───────────────────────────────────────────────────────────────────────────────┘
When prompted, choose Internet Site as highlighted above.
Next, choose a domain name for the mail system.
┌─────────────────────────────────────────┤ Postfix Configuration ├──────────────────────────────────────────┐ │ The "mail name" is the domain name used to "qualify" _ALL_ mail addresses without a domain name. This │ │ includes mail to and from : please do not make your machine send out mail from root@example.org │ │ unless root@example.org has told you to. │ │ │ │ This name will also be used by other programs. It should be the single, fully qualified domain name │ │ (FQDN). │ │ │ │ Thus, if a mail address on the local host is foo@example.org, the correct value for this option would be │ │ example.org. │ │ │ │ System mail name: │ │ │ │ maill.example.com_________________________________________________________________________________________ │ │ │ │ <Ok> <Cancel> │ │ │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Once the installation is complete, you can stop, start and enable the service using the commands below:
sudo systemctl stop postfix sudo systemctl start postfix sudo systemctl enable postfix
Then enable command enables the service to automatically start up every time the system boots up.
Configure Postfix
Now that Postfix is installed, move below to learn how to configure it.
Like many other mail servers, Postfix has many different configuration options. Some are basic while others are more advanced.
Postfix main configuration file is located at /etc/postfix/main.cf
Run the commands below to open its default configuration file:
sudo nano /etc/postfix/main.cf
The majority of Postfix settings are found in this configuration file. At the bottom of the file, you’ll find all the lines with configuration options that you’ll need to set up your environment.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = ubuntu1804.example.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = $myhostname, mail.example.com, ubuntu1804, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all
Three to four main configuration options are mostly configured in a live environment: myhostname, mydestination, mynetworks, and mail home folder.
These are details for some of the configurations above:
- myhostnme: describes the mail server hostname or system name. normally its a fully qualified hostname:
- mailsr.example.com
- mydomain: describes the domain Postfix is handling mail for
- example: example.com
- mynetworks: describes the trusted networks of remote SMTP servers that can relay through the server
- example: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
- home_mailbx: describes user’s home mailbox.
- example: home_mailbox = Maildir/
Besides the configuration options above, Postfix also comes with self-signed certificate settings that come configured on the system.
Postfix self-signed SSL certificate settings are located in the same configuration file mentioned above.
TLS configuration lines look similar to the ones below:
# TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes
Many other Postfix configurations are located in the /etc/postfix directory. You may have to review files in its main directory for more advanced configuration for help.
When connecting to the service for the first time, you will receive a warning message because they are self-signed and not CA certificates.
Conclusion:
This post shows you how to install and configure the Postfix mail server on Ubuntu. If you find any error above, please report it in the comment form below.
You may also like the post below: