Run Email Server with Sendmail on AlmaLinux 9

In this tutorial, we try to teach you to Run an Email Server with Sendmail on AlmaLinux 9 and Configure SMTP for sending messages with Sendmail.

Sendmail is a mail transfer agent that is an open-source and free software for Linux distributions. It sends and receives emails via a Simple Mail Transfer Protocol (SMTP). Typically it is installed with additional applications that enable user inbox configurations.

You can follow the rest of the article to Install Sendmail on AlmaLinux 9 and Set up SMTP for it.

Steps To Run an Email Server with Sendmail on AlmaLinux 9

You need some requirements before you start to run your Email server with Sendmail. Let’s see what we need.

Requirements

You must have access to your server as a non-root user with sudo privileges and set up a basic firewall to ensure that port 25 is allowed through the firewall which is the default port for SMTP. For this purpose, you can visit this guide on Initial Server Setup with AlmaLinux 9.

When you are done, follow the steps below to complete this guide.

Step 1 – Install Sendmail on AlmaLinux 9

First, you must run the system update with the following command:

sudo dnf update -y

Then, use the following command to install your Sendmail Email server:

sudo dnf install sendmail sendmail-cf make -y

When your installation is completed, you must edit the /etc/hosts file and define your hostname.

Find your hostname by using the command below:

hostname

Next, open the file with your favorite text editor, we use the vi editor:

sudo vi /etc/hosts

On the line starting with 127.0.0.1, add the hostname to the end as it looks below. This should be on a single line.

127.0.0.1 localhost your-hostname

When you are done, save and close the file.

Now follow the steps below to configure the SMTP with authentication and without authentication.

Step 2 – Run Sendmail on AlmaLinux 9 – SMTP Configuration with Authentication

At this point, you can configure your SMTP with authentication information. It is the mechanism by which the clients of an ISP identify themselves to the mail server through which they intend to send email.

First, you need to create a new directory inside /etc/mail directory for SMTP configuration. To do this, run the command below:

sudo mkdir /etc/mail/authinfo

Then, set the correct permission for the authentication file with the following command:

sudo chmod -R 700 /etc/mail/authinfo

Now create a new file for your SMTP authentication inside the newly created directory by using the command below:

# cd /etc/mail/authinfo
# sudo vi smtp-auth

Add the following line to the file. Just remember to replace the email address with your login email and password with your password.

AuthInfo: "U:root" "I:email-address" "P:password"

When you are done, save and close the file.

Now you need to create a hash database map for the above-created authentication. To do this, run the following command:

sudo makemap hash smtp-auth < smtp-auth

At this point, switch to the Sendmail configuration directory and edit the sendmail.mc file. To do this, run the following commands:

# cd /etc/mail
# sudo vi sendmail.mc

In the file, Add the below configurations right after the MAILER _DEFINITIONS line at the bottom of the file.

Replace “smtp.your.provider” with your email provider’s SMTP server. For example, if you’re using Gmail, the line should look like this:

dnl define(`SMART_HOST', `smtp.gmail.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/smtp-auth.db')dnl

When you are done, save and close the file.

At this point, you must rebuild the Sendmail configuration using the following commands:

# cd /etc/mail 
# sudo make

Then, restart Sendmail on AlmaLinux 9 to apply the changes:

sudo systemctl restart sendmail

Now you can start to send emails by using SMTP.

Step 3 – Run Sendmail on AlmaLinux 9 – SMTP Configuration without Authentication

If you want to send emails without authentication you can follow the steps below.

First, switch to your /etc/mail directory with the command below:

cd /etc/mail

Then, open the sendmail.mc file with your desired text editor:

sudo vi sendmail.mc

Add the below configurations to the end of the file.

Note: Replace smtp-host with your SMTP hostname.

define(`SMART_HOST',`smtp-host')dnl
define(`RELAY_MAILER', `esmtp')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

When you are done, save and close the file.

Finally, rebuild the configuration and restart Sendmail on AlmaLinux 9:

# cd /etc/mail
# sudo make
# sudo systemctl restart sendmail

That’s it you are done.

Conclusion

At this point, you have learned to Run an Email Server with Sendmail on AlmaLinux 9 and Configure your SMTP with authentication information and also without authentication. By configuring SMTP for Sendmail you can easily start to send and receive emails.

Hope you enjoy using it. You may be interested in these articles:

Restart Network Service on AlmaLinux 9 and RHEL 9

Install Cinnamon Desktop on AlmaLinux 9

Install Zoom Client on Rocky Linux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!