Set Up Mail Forwarding in Sendmail on Linux?

Introduction

Prerequisites

  • You have root or sudo privileges.
  • Sendmail is installed and running.
  • You have access to configuration files.
  • You understand basic command-line operations.

To check if Sendmail is installed, run:

sendmail -V
sudo apt update && sudo apt install sendmail
sudo yum install sendmail sendmail-cf   

Steps to Configure the .forward File

cd /home/username
nano .forward
user@example.com, user1@example.com, usman@a2zeducate.com

Steps to Configure the /etc/aliases File

  1. Edit the aliases file:
sudo nano /etc/aliases
localuser:  user@example.com
sudo newaliases
sudo systemctl restart sendmail

Steps to Configure Mail Relay in Sendmail

  1. Edit Sendmail’s configuration file:
sudo nano /etc/mail/sendmail.mc
dnl define(`SMART_HOST', `smtp.yourprovider.com')
define(`SMART_HOST', `smtp.relayserver.com')
sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
sudo systemctl restart sendmail

Testing Mail Forwarding in Sendmail

After configuring forwarding, test it by sending an email from another system:

echo "Test email" | mail -s "Forwarding Test" username@yourdomain.com

Alternative Mail Forwarding Solutions

you can use the following alternative solutions to forward mails.

Conclusion

FAQs

1. Can I forward emails to multiple addresses using Sendmail?

2. How can I verify if my emails are being forwarded?

3. What permissions should the .forward file have?

Can I forward emails without keeping a copy in my inbox?

Read Also

How to Set Up Mail Forwarding in Postfix on Linux – A Complete Guide

Previous Post
Next Post