Skip to content

Wiring SendGrid, Postmark, or Mailgun as Exim smarthost on cPanel

Configuration recipes for sending cPanel outbound mail through SendGrid, Postmark, or Mailgun smarthosts, with notes on which provider fits which workload.

When the decision is made to route a cPanel server’s outbound mail through a transactional provider, the three names that come up most are SendGrid, Postmark, and Mailgun. They have different strengths, different price models, and different operational quirks. The wiring into Exim is the same shape for all three — SMTP relay on port 587 with TLS and an API key as password — but the verification, DKIM, and feedback wiring differ enough that copying a config from one to another loses important details.

What’s happening

Each provider verifies the sending domain (DKIM CNAMEs published in DNS), authenticates SMTP submissions with an API key (not a password), and routes through their own warmed-up IP pool. They differ in: which CNAMEs they require (some use one, some three), which MAIL FROM rewrite they do (Postmark stricter than SendGrid, Mailgun configurable), how they handle bounces (Postmark exposes via API, SendGrid uses webhooks, Mailgun both), and how they price (Postmark per message, SendGrid by volume tier, Mailgun by message+features).

How to verify

Test the relay endpoint before pointing Exim at it:

openssl s_client -starttls smtp -connect smtp.sendgrid.net:587 -crlf
openssl s_client -starttls smtp -connect smtp.postmarkapp.com:587 -crlf
openssl s_client -starttls smtp -connect smtp.mailgun.org:587 -crlf

Each should complete the TLS handshake. Then authenticate with the API token as both username and password (SendGrid uses literal apikey as username; Postmark uses the Server API token; Mailgun uses the domain SMTP credentials).

The fix

  1. Choose by workload. Postmark for high-deliverability transactional mail (receipts, password resets) where the cost-per-message is acceptable. SendGrid for higher volume marketing/transactional mix. Mailgun for fine-grained tracking and webhook flexibility.
  2. Verify the domain in the provider’s dashboard. Publish the DKIM CNAMEs they generate. For SendGrid, publish s1._domainkey and s2._domainkey CNAMEs. For Postmark, the single DKIM CNAME and a Return-Path CNAME. For Mailgun, three records (DKIM, SPF, MX for bounces).
  3. Configure Exim’s smarthost in WHM > Exim Configuration Manager > Basic Editor. SMTP host: provider’s relay. Port: 587. TLS: STARTTLS required. Auth: API key as credentials.
  4. Set a custom MAIL FROM to a subdomain you own. This keeps SPF aligned to your domain rather than the provider’s, and matters for DMARC.
  5. Wire bounce handling. SendGrid sends Event Webhooks; Postmark exposes via API; Mailgun via webhooks. Whichever provider, the bounce data must feed back into your suppression list so hard-bounced recipients stop receiving mail.
  6. Test from a real cPanel account and inspect the destination headers. Confirm DKIM aligns with your domain, SPF passes, and DMARC passes. If DMARC fails despite SPF and DKIM passing, you’re probably missing the custom MAIL FROM or DKIM CNAMEs.

For organizations choosing between providers and needing the wiring to work in production from day one, Stack Harbor handles the comparison and the integration under deployment management.