Skip to content
// MAIL (SERVER) | July 9, 2026 | 4 min read

Set Up SMTP Relay with Sendmail

Stop fighting spam filters, route your outgoing mail through a relay that recipients actually trust.

Set Up SMTP Relay with Sendmail
user@server:~
user@server ~ $ uptime && df -h / | tail -1
14:22:37 up 847 days, load: 0.08
/dev/sda1 1.8T 420G 1.3T 25% /
user@server ~ $ free -h
total used free
Mem: 32Gi 4.2Gi 27Gi
user@server ~ $

Here is how to set up SMTP relay with Sendmail. Mail sent directly from a server’s own IP address gets flagged as spam more often than mail routed through a dedicated mail provider, since that provider has already built up a sending reputation you have not. Pointing Sendmail at a relay (also called a smarthost) fixes that without switching mail software. It also means one bad actor on a shared IP range does not tank your own deliverability, since the relay’s reputation carries the weight instead of your server’s.

What you need

  • A Hostner dedicated server with Sendmail installed
  • Root or sudo access via SSH
  • Hostner’s SMTP relay hostname, smtprelay.hostner.com, or the details of another relay if you prefer to use your own

Step 1: Locate the Sendmail config

Log in via SSH, then open the main Sendmail macro file. This file is where Sendmail’s behavior is defined before it gets compiled into the format the service actually reads:

~ $ sudo nano /etc/mail/sendmail.mc

Look for a line that starts with dnl and contains SMART_HOST. It is usually commented out by default, looking something like:

~ $ dnl define(SMART_HOST', smtp.your.provider’)dnl

Step 2: Set up SMTP relay with Sendmail

Replace that line with your relay’s actual details, removing the leading dnl so the line is no longer commented out. If you are using Hostner’s own relay:

~ $ define(SMART_HOST', smtprelay.hostner.com’)dnl ~ $ define(RELAY_MAILER',esmtp’)dnl ~ $ define(RELAY_MAILER_ARGS', TCP $h 587′)dnl

Port 587 is the standard submission port Hostner’s relay expects. If you use a different relay provider instead, swap in their hostname and whatever port they specify.

If your relay requires authentication, add credentials to the access database. Hostner’s relay does not require authentication for mail originating from a server on the Hostner network, so you can skip this step if that is what you are using. For any other relay that does require it, open (or create) the file:

~ $ sudo nano /etc/mail/access

Add a line in this format:

~ $ AuthInfo:your.relay.hostname “U:username” “P:password” “M:PLAIN”

Replace your.relay.hostname with that provider’s hostname, not Hostner’s, since Hostner’s own relay skips this step entirely.

Step 3: Rebuild the configuration

Sendmail does not read the .mc file directly, it needs to be compiled into sendmail.cf first:

~ $ cd /etc/mail ~ $ m4 sendmail.mc > sendmail.cf

If you edited the access file in Step 2, rebuild its hash map too:

~ $ sudo makemap hash access < access

Step 4: Restart Sendmail and test

Restart the service to load the new configuration:

~ $ sudo systemctl restart sendmail

Send a test message to confirm mail actually goes out through the relay:

~ $ echo “Test message” | mail -s “SMTP relay test” [email protected]

Check the inbox you sent it to, and check /var/log/maillog for delivery details if it does not arrive.

If it does not work

If mail is accepted locally but never arrives, outbound port 25 being blocked is a common cause on many hosting networks, providers often block it by default to cut down on spam abuse. Hostner’s relay uses port 587 specifically to avoid that restriction, so double check you configured that port and not 25. Check your firewall rules if the issue persists. If the relay itself rejects the message rather than silently dropping it, double check the credentials in your access file, a typo there is easy to miss since the file gives no immediate feedback until you actually try sending mail. For more background on smarthost configuration options, Sendmail’s own documentation on relaying explains the mechanism in more depth.

No ticket needed. A few lines in two config files, and your outgoing mail routes through a relay recipients trust, instead of getting quietly filed into someone’s spam folder.

See more guides in Docs for setting up SSL alongside your mail server.

H

Hanna Taoufik

The Hostner team writes about servers, Linux, security, and everything that comes with running your own infrastructure, so you can skip the support ticket.