October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Set Up Sendmail on an Ubuntu VPS (Smart Host, SMTP Authentication, and Testing)

A practical Sendmail setup for Ubuntu VPS users: install the packages, configure sendmail.mc, authenticate to a smart host when needed, rebuild sendmail.cf, restrict relaying and verify delivery.
Length9 min Posted Quest giverVGSources Team

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To set up Sendmail on an Ubuntu VPS, install sendmail, sendmail-cf, mailutils and the m4 macro processor; verify the VPS hostname; edit /etc/mail/sendmail.mc; regenerate /etc/mail/sendmail.cf; configure a smart host and SMTP credentials when direct delivery is unavailable; restrict relay access; restart Sendmail; and send a test message.

This procedure is based on third-party Ubuntu and Linux guides rather than current official Ubuntu or Sendmail documentation. Package names, service behavior and provider policies can differ by Ubuntu release. Treat every command as a starting point and verify it on the release image and relay service you actually use.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What you are configuring

Sendmail is the mail-transfer agent (MTA) that accepts a message from a local command or application and then hands it to the next SMTP server. On a VPS, there are two possible paths:

  • Direct delivery: Sendmail connects to each recipient domain’s mail server. This requires the VPS and its network provider to permit outbound SMTP traffic and for receiving providers to accept mail from the server’s identity.
  • Smart-host delivery: Sendmail hands all outbound mail to a designated SMTP relay. The relay performs the onward delivery. This is the usual approach when a VPS provider blocks or limits outbound port 25.

The important configuration rule is that sendmail.mc is the source file you edit. Sendmail actually reads the generated sendmail.cf, so changes in the macro file do nothing until you rebuild the configuration and restart the service.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Do not expose a newly installed server as an unrestricted relay. The access database and authentication settings must limit who can submit mail through it.

Before installing: decisions and prerequisites

Choose direct delivery or a smart host

Ask the VPS provider whether outbound TCP port 25 is allowed. If it is blocked, throttled or filtered, choose an SMTP relay that accepts authenticated submissions, commonly on port 587. The relay hostname, port, authentication method and credentials must come from that relay service. A smart host is not a workaround for missing credentials: Sendmail still needs the relay’s required authentication settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Confirm the server identity

Check /etc/hosts before running Sendmail’s setup. The localhost entry and the VPS hostname should both be present. A minimal check is:

cat /etc/hostname
cat /etc/hosts
hostname --fqdn

If the hostname shown by the commands does not match the name you intend to use, correct the operating-system hostname and its corresponding /etc/hosts entry first. A mismatched identity can produce confusing configuration and delivery errors, so do not continue until the local names are consistent.

Have administrative access and relay details ready

  • An account with sudo rights.
  • The relay hostname, such as smtp.isp.com, if you will use a smart host.
  • The relay port and authentication requirements. The procedure below describes port 587 settings because one documented configuration uses that submission port.
  • A test recipient address that you control.

Install the Sendmail packages

Install the MTA, its configuration macros and local mail utilities. The guides used for this procedure install sendmail, sendmail-cf and mailutils; one also requires m4 to regenerate the configuration.

sudo apt update
sudo apt install sendmail sendmail-cf mailutils m4

Package names and dependency prompts can vary with the Ubuntu release. If the package manager reports that one of these names is unavailable, stop and check the package set for that release rather than substituting a similarly named package at random. The current release packaging was not verified by the sources used for this guide.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

After installation, do not make manual edits to the generated sendmail.cf as your primary configuration method. Put durable changes in /etc/mail/sendmail.mc and regenerate the compiled file.

Configure the macro file

Back up the existing files

Create a copy before changing a working image:

sudo cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc.backup
sudo cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.backup

If you need to roll back, restore the macro backup, rebuild sendmail.cf, and restart Sendmail. Keeping the source and generated files paired prevents you from restoring one without the other.

Set a smart host when the VPS cannot deliver directly

Open the macro file:

sudo nano /etc/mail/sendmail.mc

Enable the smart-host definition and point it at the relay supplied by your mail provider. The documented pattern is:

define(`SMART_HOST', `smtp.isp.com')dnl

Use the exact hostname supplied by your relay. The older examples that use a provider-specific host are tied to older Ubuntu releases and provider policies; do not copy their provider details merely because the syntax looks familiar.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you are intentionally delivering directly, leave the smart-host setting disabled and first verify that the VPS permits outbound SMTP. A smart host and direct delivery are different operating modes; mixing partial settings from both makes troubleshooting harder.

Configure port 587 submission

One documented port-587 configuration sets both the relay and ESMTP mailer arguments to TCP port 587:

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl

The same configuration enables the authentication mechanisms and authentication options required by the relay, using TRUST_AUTH_MECH and confAUTH_OPTIONS. Their exact values depend on what the relay accepts, so copy the mechanism and option values specified by that service rather than inventing a value. Keep these definitions in sendmail.mc, not only in the generated file.

Add SMTP authentication safely

Create the authinfo source file

Sendmail reads relay credentials from /etc/mail/authinfo when the authentication feature is enabled in the macro file. Create that file with root-only access:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo touch /etc/mail/authinfo
sudo chmod 600 /etc/mail/authinfo
sudo nano /etc/mail/authinfo

Enter the authentication record in the syntax required by your relay. A typical record identifies the relay host and supplies a username, password and authentication mechanism; use the relay’s documented values and mechanism. Do not paste credentials into sendmail.mc, a shell history or a file readable by ordinary users.

Build the hashed map

After saving the source file, build the database that Sendmail will query:

sudo makemap hash /etc/mail/authinfo < /etc/mail/authinfo

This creates the hash map alongside the source file. Re-run the command whenever the credentials or relay hostname changes. The authentication feature must also be enabled in sendmail.mc; creating the map alone does not make Sendmail use it.

Protect and rotate credentials

  • Keep /etc/mail/authinfo owned by root and readable only by the account that needs it.
  • Use a dedicated relay credential instead of a personal mailbox password where the relay supports that option.
  • When a credential changes, edit the source file, rebuild the map, regenerate sendmail.cf, then restart Sendmail.
  • Never include the password in a test command or a support request.

Restrict who may relay

Edit /etc/mail/access to list the hosts that are allowed to relay. Start with only the local systems and networks that genuinely submit mail. Do not add an entire public address range for convenience.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
sudo nano /etc/mail/access

The access file is a source database, so rebuild its map after editing. The standard command used in the guides is:

sudo makemap hash /etc/mail/access < /etc/mail/access

Restricting relay access is separate from SMTP authentication. Authentication proves that a client knows a credential; the access database limits which hosts Sendmail will trust. Use both controls when your deployment accepts submissions from more than the local machine.

Regenerate sendmail.cf

With the macro file, authentication source and access file ready, regenerate the active configuration. There are two documented approaches:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use m4 directly

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Use the make target

sudo make -C /etc/mail

Use one method consistently after each macro-file change. The generated sendmail.cf should have a current timestamp after the command completes. If it does not, check the command’s error output and fix the macro syntax before restarting.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Start, restart and verify the service

Restart Sendmail so the daemon loads the regenerated configuration:

sudo systemctl restart sendmail
sudo systemctl status sendmail

The status command should show an active service. If it reports a failure, do not proceed to delivery testing. Recheck the last edits to sendmail.mc, the relay definitions, file permissions and the output from the m4 or make command. Restore the backed-up macro file if necessary, rebuild sendmail.cf, and restart again.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Send a controlled test message

Use the local sendmail command to submit a small message and request verbose output:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
echo "test message" | sendmail -v your@address

Replace your@address with an address you control. The -v option prints the SMTP conversation or delivery result, which helps distinguish local submission from relay failure. Confirm both that the message arrives and that it is not placed in the recipient’s spam folder.

Run a second test after any change to the smart host, authentication map, access map or generated configuration. A successful local command only proves that Sendmail accepted the message; the recipient’s mailbox and spam folder provide the final delivery check.

Troubleshoot the common failure paths

The service will not start

  • Check that /etc/mail/sendmail.mc contains valid macro syntax and that the m4 or make command completed without errors.
  • Confirm that /etc/hosts includes localhost and the server hostname.
  • Rebuild sendmail.cf after every macro edit; restarting without rebuilding leaves the old configuration active.
  • Restore the backup files if the last change introduced the failure, then rebuild and restart.

The message is accepted but never leaves the VPS

  • Verify whether the VPS provider blocks outbound port 25. If it does, configure a smart host and the relay’s submission port instead of attempting direct delivery.
  • Check the smart-host hostname for spelling and ensure the generated sendmail.cf contains the new setting.
  • For port 587, confirm that the relay and ESMTP mailer arguments were enabled and that the authentication feature is active.

Authentication fails

  • Confirm that /etc/mail/authinfo contains the relay host named in the smart-host setting.
  • Rebuild the hash map with makemap after changing the file.
  • Check that the authentication mechanism and TRUST_AUTH_MECH/confAUTH_OPTIONS values match the relay’s requirements.
  • Regenerate sendmail.cf and restart; changing only the source file does not reload it.

The relay rejects the destination or performs an unexpected lookup

Some older examples wrap the relay hostname in square brackets, such as [smtp.gmail.com], to prevent an MX lookup and force a direct connection to that host. That example is tied to an older tutorial and provider details; use bracketed notation only when your relay’s current instructions require it. Do not assume that an old provider-specific recipe remains valid.

Mail is delivered to spam

The basic test command confirms submission and delivery status, not inbox placement. Check the recipient’s spam folder and the relay’s own delivery response. Because provider reputation and DNS requirements were not established by the available guides, do not infer that a successful Sendmail setup guarantees inbox placement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You may have created an open relay

If unrelated external hosts can submit mail through the VPS, stop the service or block external access while correcting the configuration. Review /etc/mail/access, rebuild its map, regenerate sendmail.cf, and restart. Permit only the local hosts or authenticated submission paths that your application needs.

A repeatable change checklist

  1. Record the current Ubuntu release, hostname and relay settings.
  2. Back up sendmail.mc and sendmail.cf.
  3. Edit sendmail.mc for the smart host, port and authentication features.
  4. Edit /etc/mail/authinfo, protect it, and rebuild its hash map.
  5. Edit /etc/mail/access and rebuild its hash map.
  6. Regenerate sendmail.cf with m4 or make -C /etc/mail.
  7. Restart Sendmail and check systemctl status sendmail.
  8. Send a verbose test message and verify the destination mailbox and spam folder.
  9. Retest after every relay, credential, access or macro change.

What this setup does—and does not—establish

A working installation proves that the VPS can run Sendmail, accept a local message and, when configured, submit it to the selected relay. It does not establish that every Ubuntu release uses identical package defaults, that every VPS provider permits direct port-25 delivery, or that a recipient will place the message in its inbox. The available procedural material was third-party guidance, and no current official Ubuntu or Sendmail documentation was located for verification. Treat release-specific behavior and relay policies as items to confirm with the image and service you operate.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.