- Install, Secure, Access and Configure Linux Mail Server (Postfix)
- Linux SMTP server
- Mail service components
- Setup Email server
- Configure Linux mail server
- myhostname
- mydomain
- myorigin
- mydestination
- mail_spool_directory
- mynetworks
- smtpd_banner
- inet_protocols
- Checking the mail queue
- Test Linux mail server
- Secure mailboxes from spam using SpamAssassin
- Securing SMTP connection
- Using Let’s Encrypt certificates
- POP3 and IMAP protocol basics
- Installing Dovecot
- Configure Dovecot
- Secure Dovecot
- Linux Mail Server
- Install, configure, secure, and deploy to production in only 10 minutes. A single software package, pre-configured and ready to go for your Linux email platform of choice.
- Linux Mail Server Ecosystem Overview
- The Issue:Too Many Open Source Components
- The Solution:Axigen as a Premium Linux Mail Server
Install, Secure, Access and Configure Linux Mail Server (Postfix)
If you want to send or receive an email, you should have a mail server. In this post, we will discuss the Linux mail server and how the SMTP (Simple Mail Transfer Protocol) works as well as other mail-related protocols, like Post Office Protocol (POP) and Internet Message Access Protocol (IMAP) and the relationship between them.
Table of Contents
Linux SMTP server
SMTP defines how to send mail from one host to another; it is also system independent, which means the sender and receiver can have different operating systems.
SMTP requires only that a server can send straight ASCII text to another server, you can do this by connecting to the server on port 25, which is the standard SMTP port.
Most Linux distros today come with two of the most common implementations of SMTP, which are sendmail and Postfix.
Sendmail is a famous and free mail server, but it has a little complex design and less secure.
The Postfix took mail server implementation one step further; they developed it with security in mind.
Mail service components
The mail service on any mail server has three components:
Mail user agent (MUA): this component that the user sees and interacts with like Thunderbird and Microsoft Outlook, these user agents are responsible for reading mail and allowing you to compose mail.
Mail transport agent (MTA): this component is responsible for getting the mail from one site to another like Sendmail and Postfix.
Mail delivery agent (MDA): this component is responsible for distributing received messages on the local machine to the appropriate user mailbox like postfix-maildrop and Procmail.
Setup Email server
We chose the Postfix mail server, which is very popular and common among system administrators today.
Postfix is the default mail server on most modern Linux distros.
First, check if it is installed on your system or not:
If not installed, you can install Postfix mail server on Red Hat based distros like this:
Then start the postfix service and enable it on system startup:
On Debian based distros like Ubuntu, you can install it like this:
It will ask you to select the type of configuration of the Postfix mail server during the installation process.
Among the four choices No configuration, Internet site, Internet with smarthost, Satellite system, and Local only, we will choose No configuration option.
Configure Linux mail server
After installing the Postfix mail server, you will need to configure it; you can find most of its configuration files under the /etc/postfix/ directory.
You can find the main configuration for Postfix mail server in /etc/postfix/main.cf file.
This file contains a lot of options like:
myhostname
You can use this option for specifying the hostname of the mail server. This is the Internet hostname, which Postfix will receive emails on it.
The hostnames could be like mail.example.com, smtp.example.com.
mydomain
This option is the mail domain that you will be servicing, like example.com
The syntax is like this:
myorigin
All emails sent from this mail server will look as though it came from this option. You can set this to $mydomain value.
You can use any option value, just precede it with a $ like $mydomain.
mydestination
This option lists the domains that the Postfix server uses for incoming emails.
It can take values like this:
mail_spool_directory
There are two modes of delivery that Postfix mail server can use:
- Directly to a user’s mailbox.
- To a central spool directory, this way, the mail will be in /var/spool/mail with a file for each user.
mynetworks
This option allows you to configure what servers can relay through your Postfix server.
This option should take local addresses like local mail scripts on your server only.
Otherwise, spammers can utilize your mail server to relay their messages and your mail server blacklisted and as a result, you will not be able to receive many emails.
This option has the following syntax:
smtpd_banner
This variable sets the message the server will send when the client after a successful connection.
It is better to change the banner to something that gives no clue the server you are using.
inet_protocols
This option specifies the IP protocol version used for server connections.
If you change the configuration files for the Postfix mail server, you need to reload the service:
When you type any configuration, you may make a mistake, you can check for errors using the following command:
This tool will help you find exactly the line and the error so you can fix it.
Checking the mail queue
Sometimes the mail queues are filled up with messages. This happens due to many reasons, like network failure or any reason that can delay mail delivery.
To check the mail queue on your Linux mail server, use the following command:
This command shows the Postfix mail queue.
If your queue is filled up and the message takes several hours to process, then you should flush the mail queue.
Now, if you check your mail queue, you should find it empty.
Test Linux mail server
After configuring the Postfix mail server correctly, you should test your mail server.
The first step is to use a local mail user agent like mailx or mail, which is a symlink to mailx.
Try to send a mail to someone else on the same server, if this works, then send to a remote site.
Then try to receive a mail from a remote site.
If you have any problems, check the logs. The log file on Red Hat based distros in /var/log/maillog file and on Debian based distros in /var/log/mail.log file or as defined in the rsyslogd configuration.
I recommend you to review the Linux Syslog Server for a detailed explanation about logs and how to configure the rsyslogd.
If you still have problems, try checking your DNS settings and check your MX records using Linux network commands.
Secure mailboxes from spam using SpamAssassin
One of the ways to fight spam is to scan the mailboxes by some tool, searching for certain patterns associated with spam.
One of the best solutions is SpamAssassin, which is open-source.
You can install it like this:
Then start the service and enable it at startup:
Once you’ve installed it, you can check the configuration in
SpamAssassin determines if an email is spam or not based on the result of the different scripts scores.
If the message has a higher score, that means a higher possibility of the mail being spam.
In the configuration file, the parameter required_hits 5 indicates that SpamAssassin will mark an email as spam if its score is five or higher.
The report_safe option takes the values 0, 1, or 2. If set to 0, it means email marked as spam is sent as it is, only modifying the headers to show that it is spam.
If it takes the value 1 or 2, SpamAssassin generates a new report message, and it sends the message to the recipient.
The value 1 means the spam message is coded as content message/rfc822, while if the value is 2, that means the message is coded as text/plain content.
The text/plain is safer since some mail clients execute message/rfc822 and could infect the client computer.
Now we need to integrate it into Postfix. The simplest way to do this is probably by using procmail.
We’ll have to create a file, named
, and add the following content:
Then we edit Postfix configuration file /etc/postfix/main.cf and change
Finally, restart Postfix and SpamAssassin services:
However, SpamAssassin sometimes does not recognize spam messages that led to mailboxes filled with spam messages.
Fortunately, you can filter messages before they enter the Postfix server using Realtime Blackhole Lists (RBLs). That will decrease the load on your mail server and keep your mail server clean.
Open the configuration file of Postfix server /etc/postfix/main.cf and change smtpd_recipient_restrictions option and add the following options like this:
Then restart your postfix server:
The above RBLs are the common ones; you can find more lists on the web and try them.
Securing SMTP connection
It is better to transfer your SMTP traffic over TLS to protect it from Man In The Middle (MITM) attack.
First, we need to generate the certificate and the key using openssl command:
Then add the following option to Postfix configuration file /etc/postfix/main.cf:
Finally, restart your postfix service:
Now, you have to choose the TLS on your client when connecting to the server.
You will receive a warning when you send a mail the first time after changing the setting because the certificate is not signed.
Using Let’s Encrypt certificates
Let’s Encrypt is a free SSL certificate provider that enables you to encrypt your traffic.
Instead of using self-signed certificates that annoy your users about trusting them, you can use this good solution.
First, install letsencrypt:
Or if you are using Debian based distro, you can use the following command:
Then run letsencrypt like this:
You should replace yourdomain.com with your actual domain.
After answering the prompted questions about the contact email, the email server domain, and the license, everything should be OK now.
The certificates will be in:
One last thing you have to do, which is making postfix use those certificates, you can use the following commands:
Don’t forget to replace yourdomain.com with your actual domain.
Finally, restart your postfix server:
POP3 and IMAP protocol basics
So far we’ve seen how SMTP mail server sends and receives emails without problems, but consider the following situations:
- Users need local copies of email for offline viewing.
- mbox file format is not supported. The mbox format is used by many mail user agents like mailx and mutt.
- Users cannot stay connected to a fast network to grab a local copy to read offline.
- Some mail servers don’t give access to the shared mail spool directories for security reasons.
To handle these cases, you should use the mail access protocols.
The most common two popular mail access protocols are Post Office Protocol (POP) and Internet Message Access Protocol (IMAP).
The idea behind POP is very simple: A central Linux mail server remains online all the time and receives and store emails for all users. All received emails are queued on the server until a user grabs them.
When a user wants to send an email, the email client relays it through the central Linux mail server via SMTP normally.
Note that the SMTP server and the POP server can be on the same system without any problem. Most servers do this today.
Features like keeping a master copy of a user’s email on the server were missing, which led to the development of IMAP.
By using IMAP, your Linux mail server will support three modes of access:
- The online mode is similar to having direct file system access to the Linux mail server.
- The offline mode is similar to how POP works, where the client is disconnected from the network except when grabbing an email. In this mode, the server normally does not retain a copy of the email.
- The disconnected mode works by allowing users to keep cached copies of their emails, and the server retains a copy of the email.
There are several implementations for IMAP and POP; the most popular one is the Dovecot server, which provides both protocols.
The POP3, POP3S, IMAP, and IMAPS listen on ports 110, 995, 143, and 993 respectively.
Installing Dovecot
Most Linux distros come with Dovecot preinstalled. However, you can install Dovecot in Red Hat based distros like this:
Debian based distros provide the IMAP and POP3 functionality in two separate packages, you can install them like this:
It will ask you to create self-signed certificates for using IMAP and POP3 over SSL/TLS. Select yes and enter the hostname for your system when prompted.
Then you can run the service and enable it at startup like this:
Configure Dovecot
The main configuration file for Dovecot is
Some Linux distros put the configuration under
directory and use the include directive to include the settings in the files.
You can use the following list of the parameters to configure Dovecot:
protocols: the protocols you want to support.
lmtp means local mail transfer protocol.
listen: IP addresses to listen on.
The asterisk means all ipv4 interfaces and :: means all ipv6 interfaces
userdb: user database for authenticating users.
passdb: password database for authenticating users.
mail_location: this entry in /etc/dovecot/conf.d/10-mail.conf file:
Secure Dovecot
Dovecot comes with generic SSL certificates and key files. Look at this file:
When a user tries to connect to dovecot server, it will show a warning because the certificates are not signed, you can purchase a certificate from a certificate authority if you want.
Or if you go with Let’s Encrypt certificates, you can point to them instead:
Don’t forget to open dovecot server ports in your iptables firewall by adding iptables rules for ports 110, 995, 143, 993, 25.
Or if you are using firewalld, you can do the following:
And again, for troubleshooting, you check the log files /var/log/messages, /var/log/maillog, and /var/log/mail.log files.
Linux mail server is one of the easiest servers to work with, especially the Postfix mail server.
I hope you find the post useful and interesting. Keep coming back.
Источник
Linux Mail Server
Install, configure, secure, and deploy to production in only 10 minutes. A single software package, pre-configured and ready to go for your Linux email platform of choice.
This article guides you through the steps of installing, performing basic configuration, and securing a Linux email server on own — physical or virtual — server. The single software package required is the full-featured Axigen all-in-one Linux email platform.
At the end of the article you will have a fully functioning Axigen installation which you can use to evaluate the product. Should you choose to deploy it in production, we’ve also included links to some articles and documentation pages with guidance on how to implement best practices when it comes to self hosting your email domains.
Linux Mail Server Ecosystem Overview
The Issue:Too Many Open Source Components
The Linux Email Server Ecosystem provides open source and free components for nearly all modules required by a complete Linux mail server (MTA, IMAP and POP3 servers, WebMail, WebAdmin, CalDAV and CardDAV). The internet also abounds in tutorials on how to mix and match these components.
For example, this tutorial provides a blueprint for installing and integrating Postfix (for SMTP), SpamAssassin, and Dovecot (for IMAP and POP3). It also instructs you on how to deploy Let’s Encrypt certificates on your SMTP Postfix-based MTA. It stops here though. If you’d want to also install a WebMail interface (e.g. RoundCube or SquirrelMail), your internet search would have to continue.
There are also some already bundled packages that pre-integrate certain components (e.g. mailu, mailinabox, etc.). These clearly come with the convenience of shorter installation times and already available client management and access tools (WebAdmin and WebMail). However, you still have to do the work of finding all the components needed for your Linux email service.
The Solution:Axigen as a Premium Linux Mail Server
Axigen does not mix and match any open sources components. All services and functionalities are built and developed by Axigen and integrated into a single process. This has the following advantages:
- 1 The tight integration greatly simplifies the installation, but also enhances the density of mailboxes supported on a certain «hardware unit»
- 2 Single vendor support 24/7/365 Support — Customers and Partners can directly access tech support by email at any time.
- 3 Axigen is easy to setup and use, and we provide all the information you need, in a single place.
Axigen also features, as a WebMail-centric email platform, a single-page dynamic web interface for having access to your emails, calendars, contacts, tasks, notes, shared folders, shared calendars, shared contacts, or shared notes.
Источник