Sendmail relay access

The joys of sendmail configuration!

Relay access in sendmail refers to the ability of a mail server to forward email messages to other mail servers on behalf of a client. This is a common scenario in many email systems, where a mail server acts as a relay for clients that don't have direct access to the internet or want to send email to recipients outside their own domain.

Here are the basic concepts:

  1. Relay host: The mail server that acts as a relay for clients. This server receives email messages from clients and forwards them to the final destination.
  2. Client: The mail client that sends email messages to the relay host. The client can be a user's email client (e.g., Outlook, Thunderbird) or another mail server.
  3. Relay access: The permission granted to a client to send email messages through the relay host to the final destination.

To configure relay access in sendmail, you need to modify the sendmail.cf file and the access database. Here's a step-by-step guide:

Step 1: Edit the sendmail.cf file

Open the sendmail.cf file in a text editor and add the following lines:

FEATURE(`access_db')
FEATURE(`relay_hosts_only')

The first line enables the access database, which allows you to specify which hosts are allowed to relay email through your server. The second line restricts the relay to only allow email from the specified hosts.

Step 2: Create the access database

Create a new file called access in the /etc/mail directory (or the equivalent directory on your system). This file contains the rules for relay access.

Here's an example access file:

@:include=/etc/mail/access
@:include=/etc/mail/access.local

*   OK
localhost   OK
@       OK

The first line includes the default access rules from the /etc/mail/access file. The second line allows the localhost host to relay email. The third line allows any host (@) to relay email.

Step 3: Update the sendmail.cf file

Add the following lines to the sendmail.cf file:

define(`RELAY_HOSTS', `/etc/mail/access')
define(`RELAY_CLIENTS', `localhost @')

The first line specifies the location of the access database. The second line specifies the hosts that are allowed to relay email.

Step 4: Restart sendmail

Restart the sendmail service to apply the changes:

service sendmail restart

Testing relay access

To test relay access, you can use the telnet command to connect to your sendmail server and send an email message:

telnet your_sendmail_server 25

Enter the following commands to send an email message:

HELO client
MAIL FROM:<your_email_address>
RCPT TO:<recipient_email_address>
DATA
Subject: Test email
This is a test email.
.
QUIT

Replace your_sendmail_server with the hostname or IP address of your sendmail server, your_email_address with the email address of the client, and recipient_email_address with the email address of the recipient.

If the relay access is configured correctly, the email message should be forwarded to the recipient's email server.