October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk9 min

How to Set Up Sendmail on an Ubuntu VPS

A practical Ubuntu VPS guide to installing Sendmail, configuring a smart host and SMTP authentication, rebuilding sendmail.cf, preventing open relay abuse, and testing delivery.

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 run Sendmail on an Ubuntu VPS, install sendmail, sendmail-cf, mailutils, and the m4 macro processor; verify the server hostname; configure /etc/mail/sendmail.mc; regenerate sendmail.cf; restart the service; and send a test message. If your VPS provider filters outbound SMTP on port 25, configure a smart host (SMTP relay), add its credentials through an authinfo map, and use port 587 when required. Restrict relay access before sending production mail so the machine cannot become an open relay.

What you need before installing Sendmail

Sendmail is a mail transfer agent (MTA): it accepts messages from local programs and either delivers them directly to recipient mail servers or hands them to another SMTP server. On a VPS, the second arrangement is often more practical because hosting networks commonly limit outbound connections to TCP port 25. A smart host (also called a relay) accepts your server’s messages and performs onward delivery.

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.

The procedure below reflects commonly documented Ubuntu setups, but Sendmail defaults and package behavior can change between Ubuntu releases. Confirm that the packages and service names shown here exist in the release installed on your VPS, and use your relay provider’s current connection and authentication requirements.

  • Root or sudo access to the VPS.
  • A hostname for the VPS, with matching local name resolution.
  • An SMTP relay hostname and credentials if direct delivery on port 25 is unavailable or disallowed.
  • A destination mailbox you control for testing.

Do not expose a newly installed MTA to the internet until relay permissions are restricted and a test confirms that only intended senders can submit mail.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Install the Sendmail packages

Update the package index and install the MTA, its configuration macros, local mail utilities, and the macro processor used to build the final configuration:

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

Some guides list only the first three packages and add m4 separately. Installing all four avoids a failed configuration rebuild when the macro processor is absent. If apt reports that a package is unavailable, stop and check the Ubuntu release and enabled repositories rather than substituting a similarly named package.

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

Package installation can invoke an initial setup dialog or generate a baseline configuration. Complete that setup, then make deliberate changes in the macro source file described below; do not assume the installer chose a suitable public hostname or relay policy.

Verify the VPS hostname and /etc/hosts

Sendmail uses the system name when it creates message headers and identifies itself during SMTP conversations. Before editing Sendmail, inspect the host file:

cat /etc/hosts
hostname

The localhost entry and the VPS hostname should both be present. If the hostname is missing or resolves inconsistently, correct the host file using the naming scheme supplied by your VPS provider, then open a new shell or restart the relevant service as appropriate. A malformed host file can cause setup scripts to pause, produce an unexpected mail name, or fail when Sendmail tries to determine its local identity.

Use one consistent fully qualified name throughout your operating-system and Sendmail configuration. Avoid changing the hostname midway through troubleshooting; otherwise, a message may appear to originate from a different name than the one you tested.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Understand Sendmail’s configuration files

Sendmail normally uses two related files:

  • /etc/mail/sendmail.mc is the human-edited macro source. It contains readable directives and feature definitions.
  • /etc/mail/sendmail.cf is the generated configuration consumed by Sendmail.

Edit the .mc file, not the generated .cf file. Direct edits to sendmail.cf are difficult to maintain and will be lost when the file is regenerated. Keep a backup before changing the macro source:

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

After every meaningful edit, regenerate sendmail.cf. Two commonly documented methods are:

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
sudo make -C /etc/mail

Use one method consistently. The first command may fail at the shell redirection step on systems where your unprivileged shell cannot write to /etc/mail; in that case, run the redirection through a privileged shell:

sudo sh -c 'm4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf'

Read the command output carefully. A macro typo can produce a configuration that builds but does not behave as intended, so a successful command is not a substitute for a delivery test.

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

Choose direct delivery or a smart host

When direct delivery is appropriate

With direct delivery, Sendmail looks up the recipient domain’s mail exchanger and connects to that server, normally over SMTP port 25. This avoids a third-party relay, but it depends on your VPS network allowing outbound port 25 and on recipient systems accepting mail from your VPS address.

Why VPS users commonly need a relay

Many VPS networks restrict or block outbound port 25 to reduce abuse. A timeout or connection refusal on port 25 can therefore be a network policy issue rather than a Sendmail syntax error. A smart host lets your server submit mail to an SMTP relay using the port and authentication method that relay accepts.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Set the smart-host macro

Open the macro file:

sudo nano /etc/mail/sendmail.mc

Find the existing SMART_HOST definition, or add one in the section where other define directives appear. Replace the example relay name with the hostname supplied by your relay service:

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

Macro quoting can differ between packaged examples. Preserve the quoting style already used in your file and ensure the macro name is exactly the one expected by that file. The relay hostname is not necessarily the same as your VPS hostname or the recipient’s domain.

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

Use brackets only when the relay requires them

Some older Ubuntu tutorials write the relay as a bracketed host such as [smtp.gmail.com]. Brackets tell Sendmail to use that host literally instead of performing an MX lookup. This can be useful for a specific relay configuration, but provider details in older tutorials may no longer apply. Use brackets only when your relay’s current instructions require literal-host behavior; otherwise, use the relay hostname normally.

Configure SMTP authentication with authinfo

A relay that requires authentication needs credentials in Sendmail’s authentication map. Create or edit:

sudo nano /etc/mail/authinfo

Use the exact record format, username, password representation, and authentication mechanism specified by your relay. Do not paste credentials into a publicly readable file or commit this file to source control. The authinfo file is an input database; Sendmail reads the generated hash map, not just the plain-text source.

Build the hash database with:

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

This creates the map that Sendmail looks up at delivery time. Re-run the command whenever the credentials or relay record changes. If the command reports a parse error, inspect quotation marks, whitespace, and the record syntax required by your relay before restarting Sendmail.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

The authentication feature must also be enabled in sendmail.mc. Enable the feature in the same macro source file where you define the smart host, then regenerate sendmail.cf. Merely creating authinfo does not activate authentication.

After building the map, limit access to the credential files according to your server’s security policy. A leaked relay password can be used to send mail through the relay even if your Sendmail access rules are correct.

Use port 587 when the relay expects message submission

Port 587 is commonly used for authenticated message submission. If your relay instructs you to submit there, configure the Sendmail mailer arguments in sendmail.mc rather than assuming the default port:

define('RELAY_MAILER_ARGS', 'TCP $h 587')dnl
define('ESMTP_MAILER_ARGS', 'TCP $h 587')dnl

The same setup may require the authentication trust mechanism and authentication options to be enabled:

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.
TRUST_AUTH_MECH
confAUTH_OPTIONS

Use the exact directives and values supplied for your relay. These settings are not interchangeable with a relay that expects unauthenticated port 25 delivery. After changing them, regenerate the configuration and restart the service.

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

Restrict which hosts may relay

Relay permission is separate from the smart-host destination. The smart host tells Sendmail where to forward mail; the access database controls which connecting hosts are allowed to use your server as a relay.

Edit the access source file:

sudo nano /etc/mail/access

List only the local hosts, networks, or authenticated senders that should be allowed to relay, following the access-rule syntax already present in your file. Do not add a broad wildcard merely to make a test succeed. An unrestricted rule can turn the VPS into an open relay, allowing outsiders to send through your server and damaging its reputation.

Rebuild the access database after every change:

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

Keep the source file and generated map synchronized. If you edit /etc/mail/access but do not run makemap, Sendmail may continue using the previous policy.

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

Regenerate the configuration and restart Sendmail

Once the hostname, smart host, authentication, port, and access rules are ready, rebuild the configuration:

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

Alternatively:

sudo make -C /etc/mail

Restart the service and immediately check its state:

sudo systemctl restart sendmail
sudo systemctl status sendmail

A running service only proves that Sendmail accepted the configuration syntax. It does not prove that the relay is reachable, credentials work, or recipient systems will accept the message.

Send a test message and interpret the result

Send a small test message to an address you can inspect:

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

The -v option prints the SMTP conversation and delivery path. Save the output while troubleshooting, but remove passwords or other sensitive values before sharing logs.

Check all of the following:

  • Sendmail connects to the intended relay rather than attempting an unreachable direct delivery.
  • The connection uses the port required by the relay, such as 587 for authenticated submission.
  • The relay accepts the authentication credentials without an authentication or authorization error.
  • The final SMTP response indicates acceptance or successful hand-off.
  • The message arrives in the destination mailbox, including its spam or junk folder.

A successful hand-off means the next mail server accepted responsibility; it does not guarantee placement in the inbox. Keep the test recipient, timestamp, verbose output, and relay response together so you can distinguish a local configuration problem from downstream filtering.

Troubleshoot the most common failures

Symptom Likely area What to check
sendmail is not found Packages Confirm that sendmail and mailutils installed successfully; install the missing package with apt.
The service will not start Generated configuration Rebuild from sendmail.mc, read the error output, and undo the last macro change. Check for unmatched quotes or an invalid directive.
Port 25 times out VPS network policy or routing Use the relay supplied for your VPS and configure its required submission port instead of repeatedly retrying direct delivery.
Connection reaches the relay but authentication fails authinfo map or feature settings Verify the relay hostname, credential record, authentication feature, and regenerated hash map. Re-run makemap after correcting the source.
Changes have no effect Stale generated files Regenerate sendmail.cf and the relevant map databases, then restart Sendmail.
The relay accepts mail but it never appears Recipient filtering or spam placement Check the spam folder and the relay’s delivery status. A local “accepted” response is not an inbox guarantee.
Unexpected outside mail is accepted Relay access policy Inspect /etc/mail/access, remove broad relay permissions, rebuild its map, and restart the service.
The message identifies the wrong server Hostname or host file Recheck the VPS hostname and the localhost/hostname entries in /etc/hosts, then regenerate the Sendmail configuration.

A repeatable deployment checklist

  1. Confirm the Ubuntu release, obtain sudo access, and choose the hostname.
  2. Verify that /etc/hosts contains valid localhost and VPS-hostname entries.
  3. Install sendmail, sendmail-cf, mailutils, and m4.
  4. Back up /etc/mail/sendmail.mc.
  5. Decide whether direct port 25 delivery is permitted; if not, obtain a smart-host relay.
  6. Set the smart-host macro and, when required, the relay’s port-587 mailer arguments.
  7. Create the relay’s authinfo entry, enable authentication, and run makemap.
  8. Restrict relay clients in /etc/mail/access and rebuild that map.
  9. Regenerate sendmail.cf with m4 or make -C /etc/mail.
  10. Restart Sendmail and verify its service status.
  11. Send a verbose test message and check both acceptance output and the recipient’s spam folder.

Repeat the regeneration and map-building steps whenever you change the macro file, authentication records, or access policy. Keep a dated backup of the last known-good configuration so you can restore service without guessing which directive changed.

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.

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

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 from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.