Sendmail configuration is notoriously complex. Its configuration file is sendmail.cf, located in the /etc/mail directory. Due to the cryptic and arcane syntax of sendmail.cf, few people attempt to modify this file directly to configure a Sendmail server. Generally, we use the m4 macro processor to generate the required sendmail.cf file. This creation process also requires a template file; by default, the system provides a sendmail.mc template file in the /etc/mail directory.
We can generate the sendmail.cf file based on the simple and intuitive sendmail.mc template, without needing to edit the sendmail.cf file directly. The sendmail.mc template can be directly modified to achieve the goal of customizing the sendmail.cf file. Here are the steps to create the sendmail.cf file:
(1) Back Up the Original sendmail.cf File
Run the following command in the terminal command window:
cp /etc/mial/sendmail.cf /etc/mail/sendmail.cf.BAK
(2) Generate the sendmail.cf File
Generate the sendmail.cf configuration file based on the sendmail.mc template file and export it to the /etc/mail/ directory:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
(3) Restart the Sendmail Service
[root@ahpeng root] /etc/rc.d/init.d/sendmail restart
Obviously, using the m4 macro compilation tool to create the sendmail.cf file is more convenient, less error-prone, and can avoid damage caused by certain macros with security vulnerabilities or that are outdated. A sample sendmail.mc template roughly contains the following content:
divert(-1)dnl
……
include('/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID('setup for Red Hat Linux')dnl
OSTYPE('linux')dnl
……
dnl #
dnl define('SMART_HOST','smtp.your.provider')
dnl #
define('confDEF_USER_ID',''8:12'')dnl
define('confTRUSTED_USER', 'smmsp')dnl
dnl define(′confAUTO_REBUILD′)dnl
……
Here is an introduction to the syntax composition of the sendmail.mc template:
dnl: Used to comment out items; the dnl command also marks the end of a command.
divert(-1): Placed at the top of the mc template file to make the m4 program output more streamlined.
OSTYPE ('OperationSystemType'): Defines the operating system type used; obviously, linux should replace OperationSystemType here. Note that the corresponding OS type must be enclosed with a backtick and a single quote.
define: Defines some global settings. For Linux systems, after setting OSTYPE, you can define the following global parameters; if not defined, default values are used. Here are two simple examples: define('ALIAS_FILE'锛?#39;/etc/aliases')
Defines the save path for the alias file, default is /etc/aliases
define('STATUS_FILE', '/etc/mail/statistics')
Sendmail status information file.
The above is just a simple syntax explanation for sendmail.mc; for more parameter meanings and configuration information, see http://www.sendmail.org/m4/tweaking_config.html.
Creating Email Accounts for New Users
Setting up an email account for a new user in Linux is relatively simple; you just need to add a new user to the Linux system. Click the “Main Menu → System Settings → Users and Groups” menu item to open the “Red Hat User Manager” dialog box, click the “Add User” button, and in the “Create New User” dialog box that appears, specify the username and login password, as shown in Figure 3.
Assuming we added a user Peter (password peter), this user now has the email address [email protected] (replace YourDomain.com here with your own domain name).
The above process can also be achieved by running the following command in the terminal command window:
[root@ahpeng root]#adduser peter -p peter
Setting Aliases for Email Accounts
Some users want to use multiple email addresses. Do they need to create multiple email accounts? We can use aliases to solve this problem.
For example, user peter wants to have the following 3 email addresses:
[email protected], dearpeter@ YourDomain.com, truepeter@ YourDomain.com.
We can set up such aliases through the following steps:
Add a new account peter; then use a text editor like vi or Kate to open /etc/aliases, and add the following two lines inside:
dearpeter: peter
truepeter: peter
Save /etc/aliases and exit.
However, this alone won’t make Sendmail accept the new aliases; we must run the newaliases command in the terminal command window to request Sendmail to re-read the /etc/aliases file. If everything is correct, you should see a response message similar to the following:
[root@ahpeng root]# newaliases
/etc/aliases: 63 aliases, longest 10 bytes, 625 bytes total
This way, emails sent to peter can use 3 email addresses, and peter only needs to use the single email account [email protected] to receive all emails sent to those 3 addresses.
Specifying Mailbox Capacity Limits
When a mail server provides services for many people, unlimited email storage can easily fill up the server’s hard drive, creating a burden on the hard disk. If you do not want to provide users with unlimited email storage space, you can use “mail quotas” to give users a limited temporary storage space.
In fact, this is implemented using the disk quota feature. The temporary storage space for email is in the /var/spool/mail directory; you simply need to set the maximum space each user can use in this directory through disk quotas.
Enabling POP and IMAP Functionality
Up to this point, we can already use Outlook Express to send emails, or log into the server to use mail and pine commands to receive and manage mail. However, we still cannot use clients like Outlook Express to download mail from the server because Sendmail does not have POP3 (IMAP) functionality built-in, so we must install it ourselves.
(1) Installing POP and IMAP Servers
When installing Red Hat Linux 9.0, you can choose to install POP and IMAP servers. You can verify this by running the following command in the terminal command window:
[root@ahpeng root]# rpm -qa imap
imap-2001a-18
If it is not installed, insert the second installation CD into the CD-ROM drive, then run the following commands in the terminal command window to start the installation:
[root@ahpeng root]#cd /mnt/cdrom/RedHat/RPMS
[root@ahpeng root]#rpm -ivh imap-2001a-18.i386.rpm
Since Red Hat Linux 9.0 has packaged POP and IMAP into a single suite, installing imap-2001a-18.i386.rpm will install both servers simultaneously.
(2) Starting POP and IMAP Services
To successfully start the POP and IMAP servers, first ensure these services exist in the /etc/services file and that the following services are not commented out with a # (if they are, the comments must be removed).
imap 143/tcp imap2 # Interim Mail Access Proto v2
imap 143/udp imap2
pop2 109/tcp pop-2 postoffice # POP version 2
pop2 109/udp pop-2
pop3 110/tcp pop-3 # POP version 3
pop3 110/udp pop-3
After modifying the /etc/services file, you next need to customize the corresponding service configuration files:
To start the POP3 service: You must modify the /etc/xinetd.d/ipop3 file, changing “disable=yes” to “disable=no”, and save the file. Finally, you must restart the xinetd program to read the new configuration file and make the settings take effect:
[root@ahpeng root]#/etc/rc.d/init.d/xinetd reload
To start the IMAP service: You must modify the /etc/xinetd.d/imap file, changing “disable = yes” to “disable =no”, and save the file. Finally, you must restart