emailr_
All articles
explainer·7 min

What is an email relay and when to use one

infrastructurerelaysmtp

Summary

An email relay is a server that forwards email on behalf of other systems. It handles the complexity of email delivery so your applications don't have to. Most transactional email services are essentially managed relay services.

A startup's engineering team built their application to send emails directly from their web servers. It worked fine in development. In production, emails started disappearing. Gmail rejected them. Microsoft throttled them. Their IP addresses had no reputation, their servers weren't configured for email delivery, and they were learning the hard way that sending email is harder than it looks.

They switched to an email relay service. Within a day, their delivery problems vanished. The relay handled authentication, managed IP reputation, dealt with throttling and retries, and generally did all the things their web servers couldn't do well.

Email relays exist because sending email reliably is a specialized problem. Most applications shouldn't try to solve it themselves.

What a relay actually does

An email relay accepts email from one system and forwards it to another. Your application sends email to the relay; the relay sends it to the recipient's mail server. The relay sits in the middle, handling the complexity of actual delivery.

This might sound like unnecessary indirection, but the relay provides crucial services. It maintains relationships with major email providers. It manages IP reputation across all its customers. It handles authentication (SPF, DKIM, DMARC) correctly. It implements proper retry logic for temporary failures. It manages throttling to avoid overwhelming recipient servers.

Your application just needs to hand off the email. The relay handles everything else.

The term "relay" can refer to different things in different contexts. An SMTP relay is any server that forwards email. A smart host is a relay that a mail server is configured to route all outbound email through. Transactional email services like SendGrid, Mailgun, or Amazon SES are essentially managed relay services with additional features.

Why applications need relays

Sending email directly from application servers creates problems that relays solve.

IP reputation is the biggest issue. Email providers judge senders by their IP address history. A new IP with no history is treated with suspicion. An IP that's been sending spam (even from previous tenants in a cloud environment) is blocked. Building and maintaining IP reputation requires consistent sending volume and good practices over time—not something most applications can provide.

Authentication configuration is complex. SPF records need to authorize your sending IPs. DKIM requires key generation, DNS records, and proper signing. DMARC ties it together. Getting this right on application servers, especially in dynamic cloud environments where IPs change, is challenging.

Delivery handling requires sophistication. When a recipient server returns a temporary error, you need to retry with appropriate backoff. When it throttles you, you need to slow down. When it rejects permanently, you need to stop trying. Implementing this correctly is non-trivial.

Monitoring and debugging need infrastructure. When emails fail, you need to know why. Relays provide logs, analytics, and debugging tools that would be expensive to build yourself.

Types of email relays

Different relay configurations serve different needs.

Managed transactional email services (SendGrid, Mailgun, Postmark, Amazon SES) are the most common choice for applications. They provide APIs and SMTP endpoints, handle all delivery complexity, and offer analytics and debugging tools. You pay based on volume.

Self-hosted relays (Postfix, Exim configured as relays) give you control but require expertise. You manage the servers, maintain reputation, configure authentication. This makes sense for organizations with specific compliance requirements or very high volumes where managed service costs become significant.

ISP or hosting provider relays are sometimes available as part of hosting packages. Quality varies widely. Some are well-maintained; others are shared with spammers and have terrible reputation. Evaluate carefully before relying on these.

Internal relays within organizations route email between internal systems and the outside world. They might add compliance headers, scan for sensitive data, or enforce policies. These typically forward to another relay or directly to recipients.

SMTP relay vs API

Modern email services offer two ways to send: SMTP relay and HTTP API. Both accomplish the same goal but work differently.

SMTP relay uses the traditional email protocol. Your application connects to the relay's SMTP server, authenticates, and sends the email using standard SMTP commands. This works with any system that can send email—legacy applications, WordPress plugins, network devices, anything with SMTP support.

HTTP APIs are more modern. Your application makes an HTTP POST request with the email content as JSON or form data. This is often easier to integrate into web applications, provides richer error responses, and can offer features beyond basic email sending.

For new applications, APIs are usually preferable. They're easier to work with, provide better feedback, and integrate naturally with modern development practices. For legacy systems or devices that only support SMTP, relay access is essential.

Many services offer both, letting you choose based on your needs. Some features might only be available through one interface or the other.

Configuring applications to use relays

Most applications and frameworks have straightforward relay configuration.

For SMTP relay, you typically configure: the relay hostname, the port (usually 587 for submission with TLS), authentication credentials (username and password or API key), and TLS settings. The application then sends all outbound email through this relay.

For API integration, you use the service's SDK or make HTTP requests directly. Configuration involves API keys and endpoint URLs. The integration is usually more code but provides more control and better error handling.

Environment-specific configuration is important. Development environments might use a service like Mailtrap that captures emails without delivering them. Staging might use the production relay but send to test addresses. Production uses the real relay with real delivery.

Credential management matters. API keys and SMTP passwords should be stored securely, not hardcoded. Use environment variables or secrets management systems. Rotate credentials periodically.

When to use your own relay

Most applications should use managed relay services. But some situations warrant running your own.

Extreme volume can make managed services expensive. If you're sending hundreds of millions of emails monthly, the per-email costs add up. Running your own infrastructure might be more economical, though you're trading money for operational complexity.

Compliance requirements sometimes mandate control over email infrastructure. Healthcare, finance, and government organizations might need to ensure emails never pass through third-party systems, or need specific audit capabilities that managed services don't provide.

Specific technical requirements might not be met by managed services. Custom authentication schemes, unusual protocols, or integration with legacy systems might require a self-hosted solution.

If you do run your own relay, expect significant operational overhead. You'll need to manage IP reputation, handle blacklist issues, maintain authentication configuration, monitor delivery, and stay current with evolving email standards. This is a specialized skill set.

Relay security considerations

Relays are attractive targets for abuse. A compromised relay can send spam that damages your reputation and potentially gets you blacklisted.

Authentication is essential. Never run an open relay that accepts email from anyone. Require authentication for all submissions. Use strong credentials and rotate them periodically.

Rate limiting prevents abuse from compromised credentials. If an attacker gets one set of credentials, rate limits contain the damage while you respond.

Monitoring for anomalies catches problems early. Sudden volume spikes, unusual recipient patterns, or sending at odd hours might indicate compromise. Alert on these patterns.

Sender verification ensures only authorized addresses can send. If your relay is supposed to send from @yourcompany.com, reject attempts to send from other domains.

Frequently asked questions

Is using a relay the same as email forwarding?

Not quite. Forwarding takes received email and sends it elsewhere. Relaying takes email from an application or server and delivers it to recipients. The relay is part of the sending path, not the receiving path.

Will using a relay improve my deliverability?

Usually yes, significantly. Good relay services maintain strong IP reputation, handle authentication correctly, and manage delivery professionally. This almost always beats what application servers can do directly.

Can I use Gmail or Outlook as a relay?

Consumer email services have strict sending limits and aren't designed for application use. Google Workspace and Microsoft 365 offer SMTP relay features for their customers, but with limitations. For serious application email, use a dedicated service.

What's the difference between a relay and an MTA?

An MTA (Mail Transfer Agent) is any server that transfers email. A relay is an MTA specifically configured to forward email from other systems rather than being the origin or final destination. All relays are MTAs, but not all MTAs are relays.

e_

Written by the emailr team

Building email infrastructure for developers

Ready to start sending?

Get your API key and send your first email in under 5 minutes. No credit card required.