Setting up a mail server on Linux is actually not that difficult. Let’s take Red Hat Linux 9.0 as an example. The available mail server suites on Linux include Sendmail and Qmail. Qmail focuses more on security issues; if you need a secure mail gateway, it’s a good option. Sendmail, on the other hand, is known for its stability, portability, and ensuring there are no bugs, plus you can find a wealth of usage resources online. Therefore, Linux systems generally choose Sendmail to build this service, and this article is also based on Sendmail.
Setting Up a Mail Server on Linux Part 1: Installing Sendmail
When you fully install Red Hat Linux 9.0, Sendmail is automatically built-in, version 8.12.8-4. If you are not sure whether Linux has Sendmail installed, you can check by entering the following command:
[root@ahpeng root] rpm –qa grep sendmail
If you confirm it is not installed, in the graphical interface, click “Main Menu – System Settings – Add/Remove Applications” in sequence, then in the opened “Package Management” window, select the “Mail Server” option, click “Update” and follow the prompts to install.
Another method is: directly insert the first Linux installation CD, select the sendmail-8.12.8-4.i386.rpm installation package under the /RedHat/RPMS directory, then run [root@ahpeng RPMS] # rpm -ivh sendmail-8.12.8-4.i386.rpm to start the installation. Then use this same method on the third installation CD in the same directory to install sendmail-cf.8.12.8-4.i386.rpm and sendmail-doc.8.12.8-4.i386.rpm sequentially.
Setting Up a Mail Server on Linux Part 2: Starting the Sendmail Service System
The author recommends using the Sendmail command with parameters to control the mail server’s operation: [root@ahpeng root]# sendmail -bd –q12h. The parameters following it are explained as follows:
-b: Sets the Sendmail service to run in the background.
-d: Specifies that Sendmail runs as a Daemon (daemon process).
-q: Sets that when Sendmail cannot successfully send a mail, it saves the mail in the queue and specifies the save time. The 12h above means keeping it for 12 hours.
Additionally, to check if the Sendmail server is running normally, you can use the command line: [root@ahpeng root] # /etc/rc.d/init.d/sendmail status.
Setting Up a Mail Server on Linux Part 3: Configuring Sendmail
The configuration syntax of sendmail.cf is quite difficult to understand. Generally, documentation uses the m4 macro processor to generate the required sendmail.cf file (using the m4 compilation tool generally avoids errors and can also prevent certain macros with security vulnerabilities from damaging the server). Its configuration file is located at /etc/mail/sendmail.cf. A template file is also needed during the creation process; Linux comes with a template file located at /etc/mail/sendmail.mc. Therefore, you can directly achieve the goal of customizing the sendmail.cf file by modifying the sendmail.mc template, instead of struggling with those hard-to-understand configuration commands. The configuration steps are:
Step 1: Use the template file sendmail.mc to generate the sendmail.cf configuration file, and export it to the /etc/mail/ directory. The command line is: m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf
Step 2: Then restart sendmail using the command line: [root@ahpeng root] /etc/rc.d/init.d/sendmail restart.
At this point, the mail service system configuration is complete and it is working normally. The next step is to create specific accounts.
Setting Up a Mail Server on Linux Part 4: Creating New Email Accounts
This step is relatively simple; you just need to add a new user in Linux. Go to “Main Menu – System Settings – Users and Groups” in sequence, then open the “Red Hat User Manager” dialog, click the “Add User” button, and enter the username and password in the subsequent “Create New User” window.
The command line method is: [root@ahpeng root]#adduser mailA -p Pass, which means creating an account named mailA with the password Pass.
Setting Up a Mail Server on Linux Part 5: Limiting the Mailbox Capacity for a Single User
If user email capacity is not limited, the server’s hard disk will be overwhelmed. This can be achieved using the “mail quota” function: Because the temporary storage space for emails is located in the /var/spool/
mail directory, you just need to set the maximum space each email account can use in this directory through disk quotas.
Setting Up a Mail Server on Linux Part 6: Setting Multiple Email Addresses for a Single User
Using aliases (alias) can solve this problem. Aliases are one of Sendmail’s most important features. They are defined in the aliases text file, whose location is specified by sendmail.cf, generally in the /etc directory. For example, if the mailA user we created earlier wants to have two email addresses: [email protected] and [email protected], you can set it up like this:
First, add a new account mailC, then use a Linux text editor to open /etc/aliases, and add these two lines inside: dearpeter: mailC and truepeter: mailC; then run the newaliases command in the command window to require Sendmail to re-read the /etc/aliases file. If everything is correct, a response message will appear, indicating successful configuration. This way, you can use two addresses to send mail to mailC, and mailC only needs to use one account to receive all emails sent to the above two addresses.
After the above steps, you should be able to send emails normally using Outlook Express. However, you still cannot use Outlook Express to receive emails from the server side at this point, because Sendmail does not have POP3 functionality by default; we need to install and enable it ourselves.
1. POP3 (IMAP) Server Installation
Step 1: Use the following command line to check if the system is installed:
[root@ahpeng root]# rpm -qa imap
imap-2001a-18
Step 2: Insert the second installation CD, and use the following command lines to start the installation:
[root@ahpeng root]#cd /mnt/cdrom/RedHat/RPMS
[root@ahpeng root]#rpm -ivh imap-2001a-18.i386.rpm