Sendmail forward domain to smtp server

A classic!

To forward a domain to an SMTP server using sendmail, you'll need to configure your sendmail configuration file (/etc/sendmail.cf on most Linux systems) and create a new alias file.

Here are the steps:

Step 1: Edit the sendmail configuration file

Open the sendmail configuration file in a text editor:

sudo nano /etc/sendmail.cf

Add the following lines at the end of the file:

# Forward domain to SMTP server
FwDomain <your_domain_name>
FwSMTP <smtp_server_name>:25

Replace <your_domain_name> with the domain you want to forward, and <smtp_server_name> with the hostname or IP address of your SMTP server.

Step 2: Create a new alias file

Create a new file in the /etc/aliases directory:

sudo nano /etc/aliases/<your_domain_name>

Add the following line to the file:

@<your_domain_name>: FwDomain

This tells sendmail to forward all email addressed to <your_domain_name> to the SMTP server specified in the FwSMTP line in the sendmail configuration file.

Step 3: Update the sendmail configuration

Restart the sendmail service to apply the changes:

sudo service sendmail restart

Step 4: Test the forwarding

Send an email to <your_domain_name> to test the forwarding:

echo "Test email" | mail -s "Test email" <your_domain_name>

The email should be forwarded to the SMTP server specified in the FwSMTP line.

That's it! Your domain should now be forwarded to the SMTP server using sendmail.