cPanel / WHM Plugin

Mailgun SMTP Relay for cPanel & WHM

Group44 Mailgun SMTP Relay sends every outgoing email from a cPanel & WHM server through Mailgun over encrypted SSL/TLS. It also sets up each hosted domain in Mailgun automatically, DNS included.

$10.00 Per Month

Mailgun SMTP Relay for cPanel WHM dashboard

Overview

Better Inbox Placement and Full Delivery Visibility

It is built for hosting providers who want better inbox placement and full delivery visibility without configuring Exim, Mailgun and DNS by hand for each domain.

Product

Group44 Mailgun SMTP Relay for cPanel & WHM

Version

1.1.0

Author

Group44 Pty Ltd · www.group44.com.au

Service

Mailgun (mailgun.com), US or EU region.

Interfaces

WHM plugin (root), cPanel page (customers), command line.

Package

group44-mailgun-cpanel-1.1.0.zip

Benefits

Headline Benefits

SSL on every message

Server → Mailgun uses SMTPS on port 465 only, with a verified certificate. Mailgun → recipient requires TLS too.

One-click domain setup

Pulls every domain from WHM, creates it in Mailgun with its own login, writes SPF/DKIM/tracking DNS and verifies it.

Nothing breaks during setup

Only verified domains are routed. If Mailgun is down, mail queues instead of being sent unencrypted.

Visibility

30-day delivery chart, per-domain events, diagnostics and an activity log in WHM; a self-service page for customers in cPanel.

How It Works

Server to Mailgun to Recipient

The plugin adds a router to the server’s Exim mail system. Every outgoing message goes to Mailgun over SSL, signed in with the sending domain’s own Mailgun login.

Mailgun SMTP Relay mail flow diagram: server to Mailgun to recipient

Catch-all domain

Senders that aren’t set up, forwards and bounces use the catch-all domain’s login.

Local mail stays local

Mail between mailboxes on the same server never leaves it.

If Mailgun can’t be reached

Mail waits in the queue and retries, so it is never sent without encryption.

Only verified domains are routed

Nothing bounces while DNS propagates.

Features

Setup, Sending, Monitoring and Testing

The plugin covers setup, sending, monitoring and testing across three interfaces: a WHM plugin for the server owner, a cPanel page for customers, and a command line for automation.

WHM: Dashboard

WHM: Domains

WHM: Settings

WHM: Tools & Tests

WHM: Activity

cPanel page for customers

Automation

Command line

What each domain setup does

Screenshots

Inside WHM and cPanel

Screenshots are from a demo server with sample domains.

Mailgun SMTP Relay for cPanel WHM dashboard

Dashboard

Status banner, domain counters, the 30-day delivered vs failed chart and 30-day account totals.

Mailgun SMTP Relay for cPanel WHM settings

Settings

Mailgun API key and region, SMTP security, SSL enforcement and automation switches.

Mailgun SMTP Relay page in cPanel for customers

cPanel page for customers

Each customer sees their own domains, DNS records with Mailgun’s valid / invalid check, a test email form, 30-day totals and recent activity.

Requirements

Before You Begin

Control panel

cPanel & WHM 110 or newer.

Access

Root SSH access.

Operating system

AlmaLinux, Rocky Linux, CloudLinux or Ubuntu (any OS cPanel supports).

Mail server

Exim 4.92+ (ships with cPanel) for SMTPS on port 465.

PHP

cPanel’s built-in PHP with the curl and openssl extensions (checked by the installer).

cPanel theme

Jupiter, for the customer page (the WHM plugin works without it).

Mailgun

An account plus a private API key (Mailgun → Settings → API Security).

Network

Outbound TCP 465 open; with CSF, check SMTP_BLOCK and TCP_OUT.

Tools

unzip on the server (yum install unzip or apt install unzip).

Mailgun trial and free plans

Mailgun trial and free plans can only send to authorised recipients until the account is upgraded.

Installation

Install in About Five Minutes

Installing takes about five minutes: upload the zip, run one script as root, then finish setup in WHM.

1

Upload the package to the server: scp group44-mailgun-cpanel-1.1.0.zip root@your-server:/root/

2

Unzip it and run the installer: log in over SSH as root and run the commands shown below

3

Read the installer output: the installer checks for cPanel and PHP, copies the files, registers the WHM plugin, installs the cPanel page, adds the 15-minute cron job and restarts cpsrvd. It ends with “✔ Group44 Mailgun SMTP Relay installed”

				
					# Upload the package to the server
scp group44-mailgun-cpanel-1.1.0.zip root@your-server:/root/

# Unzip it and run the installer
ssh root@your-server
cd /root
unzip group44-mailgun-cpanel-1.1.0.zip
cd group44-mailgun
bash install.sh
				
			

Configuration

First-Time Setup in WHM

The Dashboard shows All mail via SSL: Yes once at least one domain is verified and the relay is on.

1

Open the plugin: in WHM, go to Plugins → Mailgun SMTP Relay

2

Settings: paste the Mailgun private API key and choose the US or EU region. Click Test connection, then Save settings. SSL on port 465 is enforced automatically

3

Domains: click Set up all domains, or Set up on individual domains. Each one shows Verified, or Awaiting DNS while DNS propagates

4

Dashboard: click Turn relay on and confirm. This adds the relay to Exim and restarts it

5

Tools & Tests: click Apply TLS policy to all domains, then send a Direct SSL/SMTP test and a Send via Exim test to your own address

6

Optional, for customers: in WHM → Feature Manager, tick Mailgun SMTP Relay in the feature lists that should get the cPanel page

Maintenance

Updating and Uninstalling

Updating

Settings, domains, credentials and the API key are kept across updates. Then in Tools & Tests, click Install / repair Exim config.

				
					cd /root && rm -rf group44-mailgun
unzip group44-mailgun-cpanel-<version>.zip
cd group44-mailgun && bash install.sh
				
			

Uninstalling

The Exim relay is removed first, so mail goes back to direct delivery immediately. Domains in your Mailgun account are not deleted.

				
					cd /root/group44-mailgun
bash uninstall.sh          # keeps settings
bash uninstall.sh --purge  # also deletes settings and stored credentials
				
			

Settings Reference

Defaults and What Each Setting Does

The defaults give full SSL coverage. Most servers only need the API key and region.

API key

Default: (empty). Mailgun private key. Encrypted on save; leave blank to keep the current one.

Region

Default: US. US uses api.mailgun.net / smtp.mailgun.org; EU uses the .eu hosts. Must match your Mailgun account.

SMTP security

Default: SSL/TLS, port 465. Fixed. No plaintext or STARTTLS option.

Sending subdomain

Default: (empty). E.g. mg creates mg.example.com in Mailgun; mail still sends as @example.com. Applies to new setups.

Catch-all sending domain

Default: Automatic. Domain whose login carries mail from senders not set up (scripts, forwards, bounces). Automatic picks the first verified domain.

Route all outbound mail through Mailgun over SSL

Default: On. Every outbound message goes via Mailgun on 465. Off = only set-up domains are relayed.

Require TLS from Mailgun to recipients

Default: On. Mailgun only delivers to receiving servers that support TLS. Off = Mailgun may fall back to plaintext.

Write DNS records automatically

Default: On. Adds DKIM and tracking records and merges SPF in local DNS zones.

Open & click tracking CNAME

Default: On. Adds email.<domain> → mailgun.org for tracked links.

Auto set-up new domains

Default: Off. Cron sets up new accounts, addon and parked domains every 15 minutes.

Include parked / alias domains

Default: On. Parked domains are treated as senders in their own right.

Include subdomains

Default: Off. Also sets up cPanel subdomains.

Command Line

Commands

Run as root with /usr/local/cpanel/3rdparty/bin/php /opt/group44/mailgun/cli.php <command>.

sync

Set up every eligible domain not yet set up (–all re-applies every domain).

provision <domain>

Set up one domain.

verify <domain>

Re-check one domain’s DNS with Mailgun.

verify-pending

Re-check all domains awaiting DNS.

cron

What the scheduled job runs.

rebuild

Regenerate relay routes and the Exim config.

uninstall-exim

Remove the relay from Exim.

status

Show Exim status, settings and domain count.

Security

Security Notes

Mail is encrypted on both legs, and secrets are encrypted at rest and readable only by root.

Server → Mailgun

SMTPS on port 465 only, TLS 1.2+ with forward-secret ciphers, certificate and hostname verified, SNI sent. A failed check queues mail; it is never sent without encryption.

Mailgun → recipients

Require-TLS is set on every domain, with certificate verification on.

API calls

HTTPS only, with peer and hostname verification.

Per-domain logins

Each domain has its own Mailgun SMTP login with a random 28-character password, so one domain’s login can’t send for another.

Encryption at rest

The API key and SMTP passwords are stored with AES-256-GCM, keyed by a root-only secret.

WHM access

Root only, with a security token tied to the WHM session on every action.

cPanel access

Customers reach only their own domains through a privileged helper that checks ownership on every request.

Safe Exim changes

The relay is merged into /etc/exim.conf.local between marked lines, so WHM Advanced Editor changes are kept. A backup is taken first, and the old config is restored automatically if the rebuild fails.

No shell injection

Server commands run with argument lists, never through a shell.

Files & Locations

Where Everything Lives

Command-line usage is listed under Commands above.

				
					# Application code, assets and cli.php
/opt/group44/mailgun/

# WHM interface
/usr/local/cpanel/whostmgr/docroot/cgi/group44_mailgun/index.cgi

# API module behind the cPanel page
/usr/local/cpanel/Cpanel/API/Group44Mailgun.pm

# Privileged helper for the cPanel page
/usr/local/cpanel/bin/admin/Group44/Mailgun

# cPanel page
/usr/local/cpanel/base/frontend/jupiter/group44_mailgun/

# Settings, domain state, activity log, Exim backups (root only)
/var/cpanel/group44_mailgun/

# Per-domain relay logins read by Exim (root and the mail group only)
/etc/group44_mailgun/exim_routes

# Exim relay blocks, between GROUP44_MAILGUN markers
/etc/exim.conf.local

# 15-minute sync and verify job
/etc/cron.d/group44_mailgun
				
			

Troubleshooting

Problems, Causes and Fixes

Diagnostics: TLS to smtp.mailgun.org:465 fails

Cause: outbound port 465 blocked. Fix: in CSF, check SMTP_BLOCK and add 465 to TCP_OUT; ask your provider if they block it.

Mailgun API 401 Unauthorised

Cause: wrong key, or US/EU region mismatch. Fix: re-paste the private key; switch region in Settings.

Domain stays Awaiting DNS

Cause: records not visible to Mailgun yet, or DNS hosted elsewhere. Fix: wait for propagation; for “manual” records, add them at the external DNS provider (Details shows the exact values).

Dashboard: All mail via SSL = No

Cause: relay off, or no verified domain for the catch-all route. Fix: turn the relay on and verify at least one domain.

Send via Exim: didn’t select the Mailgun route

Cause: relay off, or the domain not verified. Fix: turn the relay on; verify the domain.

A message to one recipient fails with a TLS error

Cause: that receiving server doesn’t support TLS, and require-TLS is on. Fix: expected under strict SSL; turn off Require TLS from Mailgun to recipients if that mail must go through.

“Exim rebuild failed and was rolled back”

Cause: a conflicting custom Exim setting. Fix: the old config is already restored; check Activity for the error, fix the custom setting, then Install / repair Exim config.

Customers can’t see the cPanel page

Cause: feature not enabled. Fix: tick Mailgun SMTP Relay in WHM → Feature Manager.

Mail queues during a Mailgun outage

Cause: relay defers rather than sending without SSL. Fix: no action needed; Exim retries automatically.

FAQ

Frequently Asked Questions

Does it change inbound mail or MX records?

No. Only outbound sending is relayed.

What about mail between mailboxes on the same server?

It is delivered locally and never leaves the machine.

Are forwarded emails relayed?

Yes, with route-all on. They use the catch-all domain’s login.

Are my Mailgun domains deleted when I uninstall?

No. Only Remove in a domain’s Details, with the delete box ticked, deletes it from Mailgun.

Licence

All rights reserved. The software is licensed, not sold, for use on servers you own or administer under a valid licence from Group44 Pty Ltd. It may not be redistributed, resold, sublicensed, or have its copyright notices removed without written permission.

Order Mailgun SMTP Relay for cPanel & WHM

$10.00 per month. Questions about the plugin? Contact our team. Mailgun is a trademark of its owner. cPanel and WHM are trademarks of cPanel, L.L.C. This product is not affiliated with or endorsed by them.