Facebook tracking pixel

MailGenius

SMTP Relay Configuration: Avoid Spam & Boost Deliverability

Most SMTP relay configuration advice is too easy on the wrong problem. It treats success as “the app sent an email.” That's a low bar.

A relay that merely forwards mail can still wreck your sender reputation, trigger filtering, and create a security mess you'll spend weeks cleaning up. If you configure a relay without tight access control, proper identity signals, and real validation, you haven't finished the job. You've just built a machine that can fail at scale.

The difference matters most when teams start sending production traffic from web apps, CRMs, ticketing systems, printers, and internal tools through the same relay. That's when bad assumptions show up fast. The relay works. Delivery doesn't.

Why a Working Relay Is Not a Good Relay

The popular advice says: get the connection working, test a message, move on. That's exactly how people create fragile relay setups.

A working relay accepts mail and passes it along. A good relay does that while limiting who can use it, proving sender identity, and keeping your domain out of trouble. Those aren't “nice to have” extras. They're the part that determines whether your messages keep landing.

The real implementation problem is governance, not connectivity. Permissive relay settings can create deliverability and reputational damage, and misconfigured relays are more likely to fail silently or trigger filtering as providers tighten inbound rules, as noted in this infrastructure guidance.

That's the part most tutorials skip. They show you how to make mail flow, but they don't force you to ask who is allowed to relay, what identity the mail presents, or what happens when one internal system gets compromised.

What bad relay setups usually look like

The common failures are boring because they repeat constantly:

  • Open access: The server accepts mail from too many clients.
  • Weak scoping: Teams allow broad ranges instead of specific trusted sources.
  • No operational discipline: Nobody reviews logs, queue behavior, or outbound patterns until something breaks.
  • Identity mismatch: The relay sends mail, but the domain and infrastructure don't line up in a way receivers trust.

A lot of people think spam problems start with content. Often they start with infrastructure. If your relay looks sloppy, your email starts the race already behind.

The real target

When you handle smtp relay configuration responsibly, the goal isn't “message accepted by server.” The goal is this:

Goal Bad mindset Better mindset
Connectivity Can the app connect? Can the right app connect, and only the right app?
Security Does it send? Can it send without becoming an abuse path?
Deliverability Did the recipient server accept it? Does the message look trustworthy enough to reach the inbox consistently?

Practical rule: If your relay accepts mail from clients you can't clearly name, document, and justify, it's not configured. It's exposed.

The Core Components of SMTP Relay

SMTP relay gets simpler once you stop treating it like magic. There are only a few moving parts, and each one has a job.

At the center is the Mail Transfer Agent, or MTA. That's the software doing the sending and relaying. Postfix, Exim, and Microsoft's mail stack are common examples. Your application hands off a message. The MTA decides how to route it and how to present it to the next server.

A diagram illustrating the four core components of SMTP relay: MTAs, MX Records, SPF, and DKIM authentication.

The doors your mail uses

A lot of confusion starts with ports. People mix up submission and relay, then wonder why their setup feels inconsistent.

According to JSCAPE's explanation of SMTP ports, RFC 6409 states that “Port 587 is reserved for email message submission.” In practice, port 25 is typically used for server-to-server relaying, while 587 is the default for client or application submission. 2525 is often used as a fallback when port 25 is blocked, and TLS or STARTTLS is commonly supported on 587 and 2525.

Consider this:

  • Port 587: Front desk for apps, devices, and authenticated clients
  • Port 25: Loading dock for mail servers talking to other mail servers
  • Port 2525: Side entrance when network policies get in the way

If you point an application at the wrong door, you create avoidable friction. If you expose the wrong door too broadly, you create risk.

The identity layer

A relay also depends on DNS and authentication records to look legitimate.

Here's the mental model:

  • MX records tell other systems where mail for a domain should go.
  • SPF tells receivers which systems are allowed to send.
  • DKIM adds a signature that helps prove the message wasn't altered.
  • The relay policy decides who may submit mail in the first place.

An open relay is one that forwards mail for unauthorized users or systems. A closed relay limits that behavior to authenticated users, trusted hosts, or both. That single distinction is where good smtp relay configuration starts.

If your relay policy is vague, someone else will define it for you. Usually a spammer, a compromised device, or a provider's filtering system.

Configuring SMTP Relay on Popular Mail Servers

A relay that sends mail is easy to build. A relay that sends mail without exposing you to abuse, junk traffic, and reputation damage takes more discipline.

If you are self-hosting, keep the design boring and tight. Use a trusted host with a static IP. Define exactly which systems may submit mail. Require authentication for anything outside that boundary. Treat relay access like production firewall policy, not a convenience setting you clean up later.

For a practical Postfix pattern, the mailcow community recommends a send-only relay on a trusted VPS with a static IP, port 25 available where relay traffic requires it, and SMTP AUTH or SASL for internal systems that need to submit mail in the mailcow relay guide.

A professional data center server rack with multiple server units housed in an industrial computing environment.

Postfix

Postfix remains the safer default for many Linux teams because it is predictable and easier to audit than some alternatives. The common failure is not Postfix itself. It is admins pasting a relay snippet from a forum, widening mynetworks, and calling the job done because the app can send a test message.

A minimal pattern for a relay that accepts mail from trusted internal sources and forwards through a smarthost looks like this:

# /etc/postfix/main.cf

myhostname = relay.example.com
myorigin = example.com
mydestination =

relayhost = [smtp.provider.example]:587

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

smtp_tls_security_level = may

mynetworks = 127.0.0.0/8, [trusted-internal-range]
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

The line that deserves your attention is:

smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

That setting decides whether your server relays only for approved sources or for anyone who can reach it. Get it wrong and the server may still look fine during basic testing, right up until someone starts pushing spam through it.

Use these guardrails:

  • Keep mynetworks narrow: Only include subnets you directly control and need.
  • Prefer authenticated submission for roaming systems: Credentials are easier to revoke than broad IP trust.
  • Run the relay as send-only where possible: Fewer roles mean fewer mistakes.
  • Review queue growth and auth failures: A working relay can still be abused without detection.

Teams that route app mail through Gmail instead of a Linux relay can use MailGenius on configuring Gmail SMTP for the client-side setup details.

Exim

Exim can be a solid relay. It can also become a maintenance problem if nobody on the team really understands its policy logic.

The safe approach is the same as Postfix, but Exim gives you more ways to express it and more ways to make a bad rule look reasonable. That matters in real environments, because "mail is flowing" often hides the fact that relay permissions are broader than intended.

Check these points in every Exim deployment:

  • Relay rights are explicit: Limit them to approved hosts or authenticated users.
  • Authentication is required outside trusted networks: Do not rely on source IP alone for remote clients.
  • Outbound routing is clear: If you use a smarthost, define it cleanly and test failover behavior.
  • TLS is enabled for upstream delivery: If the upstream accepts encryption, use it.
  • Logs are readable enough to audit: If nobody can tell who submitted a message, the relay is too opaque.

If you already run Exim and know it well, keep it. If you are choosing from scratch and just need a dependable outbound relay, Postfix is usually the lower-risk option.

IIS SMTP on Windows

Windows relay problems are usually self-inflicted. An admin gets a copier or line-of-business app sending mail, then leaves relay permissions broad because tightening them might break the workflow.

The safe pattern in IIS 6.0 SMTP Manager is simple:

  1. Open the SMTP virtual server properties.
  2. Go to Access.
  3. Under Relay, choose Only the list below.
  4. Add only the specific systems that should relay.
  5. Review Authentication and avoid broad anonymous use unless the source list is tightly controlled.
  6. Set outbound delivery to the correct smart host if you are relaying upstream.
  7. Test a real outbound message from each approved sender.

The setting that saves you from a bad week is relay restriction by specific IP address. If you allow broad anonymous relay from a Windows host, the server may continue doing its job for your printer while also doing someone else's job for spam.

Here's a walkthrough if you want a visual reference before you touch the GUI:

What actually works across all servers

The pattern that holds up in production is boring for a reason:

Server Safe, working setup What causes trouble
Postfix Narrow mynetworks, SASL, outbound TLS, send-only role Broad trust ranges, copied configs, no queue review
Exim Explicit relay policy, authenticated clients, clear routing Complex defaults nobody audits
IIS SMTP Specific allowed IPs, controlled anonymous use, smart host testing Broad relay permissions added for convenience

A relay should do one job well: accept mail from approved sources and pass it upstream without turning your infrastructure into someone else's spam pipe. If your configuration only answers "does it send," you are stopping the review too early.

Using Cloud SMTP Relay Services The Smart Way

Most businesses shouldn't run their own relay unless they have a real operational reason. If your team builds products, runs campaigns, manages lifecycle email, or sends outbound sales mail, your job is to control sending behavior. It probably isn't to maintain mail infrastructure.

That's why cloud SMTP relay services are often the better call. Services like Amazon SES, SendGrid, and Mailgun give you a managed path for outbound mail, which means you spend less time debugging ports, connectors, and queue behavior.

What you offload

When you use a cloud relay provider, you usually offload the messy parts that self-hosters underestimate:

  • Infrastructure upkeep: You're not babysitting the relay host.
  • Credential and access patterns: The provider usually gives you a cleaner submission workflow.
  • Operational troubleshooting: Their logs and dashboards are often easier for app teams to use than raw MTA logs.
  • Policy enforcement: Their setup nudges you toward authenticated sending instead of sloppy relay exposure.

That doesn't mean a provider fixes everything. It doesn't. If your domain identity is weak, your content is poor, or your sending practices are reckless, a cloud provider won't magically turn that into clean inbox placement.

What smart adoption looks like

A clean rollout usually follows this pattern:

  1. Verify your sending domain with the provider.
  2. Publish the DNS records they require.
  3. Generate SMTP credentials or use their API if the application supports it.
  4. Route only the mail streams that belong there.
  5. Test using real destination providers, not just an internal inbox.

A cloud relay is not a shortcut around discipline. It's a shortcut around running the plumbing yourself.

Generally, that's the right trade. You get a managed submission path and spend your energy on segmentation, bounce handling, content quality, and domain reputation instead of patching mail servers.

When self-hosting still makes sense

Self-hosting can still be reasonable if you have internal systems, appliance traffic, legacy apps, or strict routing requirements that don't fit neatly into a third-party platform. But if you go that route, own the consequences. You're responsible for access control, DNS alignment, transport security, monitoring, and abuse prevention.

If that list sounds larger than the business value of self-hosting, use a provider.

How to Secure Your Relay and Prove Your Identity

A relay has to do two jobs at the same time. It has to block unauthorized use, and it has to give receiving systems enough proof that your mail is legitimate. If either side is weak, deliverability suffers.

Reliable SMTP relay depends on combining network trust with DNS authorization. Administrators are told to use a static IP, publish MX records, and add an SPF record such as v=spf1 mx ~all to authorize senders, as described in this Windows Server SMTP relay configuration guide from DuoCircle.

A diagram illustrating essential security measures for SMTP relay, including authentication, data protection, and access control.

Job one is proving where mail came from

Start with source legitimacy.

SPF tells receivers which systems are allowed to send for your domain. It's not a complete trust system by itself, but it's foundational. If your relay sends mail and your SPF policy doesn't account for it, you're forcing receivers to guess.

Reverse DNS matters too. If the sending IP resolves to something inconsistent, generic, or unrelated to the identity your message claims, the mail looks suspicious. Receivers don't need a dramatic reason to mistrust you. They just need enough friction to downgrade confidence.

For Microsoft-heavy environments, teams often benefit from a focused reference like Ollo's guide for enterprise Microsoft 365 security, especially when relay traffic, domain authentication, and policy alignment need to coexist.

Job two is proving the message stayed intact

DKIM signs the message so receiving systems can verify that the content wasn't altered in transit. Without DKIM, forwarding and infrastructure hops can make trust decisions harder, especially when SPF alone isn't enough.

This is why “mail sends fine” isn't the right test. A message can send fine and still arrive looking unauthenticated, inconsistent, or tampered with.

Use an SPF and DKIM checker to confirm the basics are visible from the outside. Internal assumptions don't count.

Security check: If you haven't validated what receivers see for SPF and DKIM, you're still working from theory.

Job three is telling receivers what to do with failures

DMARC gives receiving providers policy instructions when authentication fails. It also helps you align the identity in visible From addresses with the technical authentication behind the message.

You don't need to overcomplicate the logic:

  • SPF and rDNS support source legitimacy
  • DKIM supports message integrity
  • DMARC ties policy and alignment together

Access control is separate from identity

A lot of admins mix these together. Don't.

Authentication records prove who is allowed to send for a domain. SMTP AUTH or SASL proves whether a client is allowed to use the relay. Those are different control planes.

Use both. A relay that has perfect DNS identity but weak access control can still become an abuse channel. A relay with strict access control but weak DNS identity can still struggle with filtering.

The safe setup is layered:

Layer Purpose Failure mode
Relay access policy Limits who may send Open relay risk
SPF and rDNS Supports source trust Identity mismatch
DKIM Protects message integrity Weak authentication signal
DMARC Enforces alignment policy Receivers make harsher assumptions

Validate and Troubleshoot Your SMTP Configuration

A relay that sends one message is easy to build. A relay that stays secure, passes authentication checks, and keeps your domain out of trouble is the one worth trusting.

Screenshot from https://mailgenius.com

Start by testing from outside your environment. Sending to your own inbox proves very little because local allowlists, cached credentials, and familiar routing can hide bad assumptions. What matters is how the message looks to a receiving system that has no reason to trust you.

The first pass is simple. Look at the failure type and sort it correctly.

  • Connection refused: The SMTP service is not listening on the port you expect, the host name points to the wrong place, or a firewall is blocking traffic.
  • Authentication failed: The relay expects a different username format, password, auth method, or submission port.
  • Relay access denied: The relay policy is blocking the client because the source IP is not allowed or the client did not authenticate.
  • Accepted but delivered poorly: The handoff worked. Your trust signals did not.

That last case wastes the most time because admins keep troubleshooting transport when the actual problem is reputation or identity. If the relay accepts mail and remote systems still filter it, stop staring at the SMTP session and inspect the message headers, SPF result, DKIM result, and alignment.

Check the full path. Confirm the application connected to the right relay, the relay applied the policy you intended, the message left on the route you expected, and the receiving side saw the same sender identity you thought you were presenting. A passed login test only proves the client got in. It says nothing about whether the message was safe to send or likely to land well.

Use an external test message to validate the result. Send from the configured relay to the MailGenius test address using the specific checker already referenced in this article, then review the authentication and spam signals it reports. That gives you a receiver-side view instead of an internal guess.

If the setup looks correct but delivery is still unstable, check if your domain is blacklisted. A clean configuration cannot fully offset a damaged sending history.

One more hard rule. Keep a copy of the raw headers from a good message and a bad one. Compare them. That habit catches a lot of relay mistakes fast, especially when different apps, devices, or teams are sending through what they assume is the same configuration.

A safe SMTP relay configuration keeps working under pressure. It does not turn into an open relay, it does not fail authentication on some paths, and it does not chip away at your sender reputation while messages continue to leave the queue.

Free Email Spam Test:

Will your Email Land in the Spam Folder?

Send an email to the address below to see your Spam Score:
loading...
MailGenius users test over 1M emails per year! By using our Email Tester, you will agree to our Privacy Policy and Terms of Service. The sending email address will receive emails from MailGenius. All tests are hosted on public links.

Try MailGenius Today

Run a Free Email Deliverability Test - Send an Email to the Address Below, then Click “See Your Score”:

Free Email Spam Test:

Will your Email Land in the Spam Folder?

Send an email to the address below to see your Spam Score:
loading...
MailGenius users test over 1M emails per year! By using our Email Tester, you will agree to our Privacy Policy and Terms of Service. The sending email address will receive emails from MailGenius. All tests are hosted on public links.

Try MailGenius Today