Mailgun is an automated email service that enables you to send, receive, and track emails from your websites and applications. It also facilitates email management for marketing and other purposes.
NB: Port 25 is closed for connection on VMs by default. If you want to open port 25, buy Mail Bridge and configure it in Starlight™ Manager.
To configure the SendGrid email on WHM, please use this guide.
Please follow the steps below to configure the Mailgun service and Email System for your domain name on the WHM side:
Step 1. Sign up for Mailgun. They suggest many account plans at different prices that you can see here:

You can sign up and register an account for free. In this case, ensure the “Add payment info” checkmark is not selected.
NB: Accounts without a credit card are limited to sending 100 messages a day:

Once everything is filled in, click on “Create Account”.
Step 2. Verify your email account by clicking on the “Verify your email address” button inside the corresponding email from Mailgun:

Step 3. Set up the Mailgun Sender Authentication. There are two ways of doing that:
Method 1:
Log into your Mailgun account >> click on the “Send” section of the menu on the left >> “Sending” >> “Domain Setting;
Inside the “Domain Settings” menu, go to the “Setup” section;
Add authorized recipients by entering a needed email address into the “Email address” field >> click “Add”:

After that, you will receive an email to the specified email address. To confirm its addition, press the "I Agree" button:

You will be redirected to a new tab in the browser. Click on the "Yes" button to confirm the email address addition:

Once done, you’ll receive a “Success” message that means the email account in question was added:

Method 2:
Log into your Mailgun account >> click on the “Send” section of the menu on the left >> “Sending” >> “Domains”. From this section, click on the “Add new domain” button:

You will be redirected to a page from where it’s possible to add a new domain to the Mailgun system. Enter the desired domain into the “Domain name” field, choose the needed options and advanced settings, and click on “Add Domain”:

After that, it is necessary to verify the domain name added by configuring the corresponding TXT and MX DNS records for the domain.
The list of the records that should be added as well as their status can be checked in your Mailgun account >> the “Send” section of the menu on the left >> “Sending” >> “Domains” >> go to the “DNS Records” section.
Once the DNS records are created for the domain, click the "Verify" button on the top right:

NB: It may take up to 24-48 hours for the DNS records to propagate.
Once the propagation is over and all the needed DNS records are added to the domain, the Mailgun system will verify it. The domain will now be listed under the “Domains” section of the “Sending” menu:

Step 4. The next step will be configuring SMTP settings for the email account on the WHM side.
To get the needed SMTP credentials log into your Mailgun account >> click on the “Send” section of the menu on the left >> “Sending” >> “Domain Settings”. From this section, open the “SMTP credentials” tab.
Copy the value under the “Login” field, reset the password and save the details for the next step:

Step 5. To configure SMTP settings on the WHM side go to WHM >> “Service Configuration” >> “Exim Configuration Manager” >> open the “Advanced Editor” tab. Search for “Section: AUTH” and add the following code inside:mailgun_login:driver = plaintextpublic_name = LOGINhide client_send = : mail@yourdomain.com : Password
where mail@yourdomain.com should be the same as the value from the “Login” field in step 4 (postmaster@sandbox6c123456789ee2.mailgun.org) and Password - the one that was reset in the previous (4th) step.
Step 6. After that, look for “Section: ROUTERSTART” and add the following code there:mailgun:driver = manualroutedomains = ! +local_domainstransport = mailgun_transportroute_list = "* smtp.mailgun.org::587 byname"host_find_failed = deferno_more
Step 7. Search for “Section: TRANSPORTSTART” and add one more code:mailgun_transport:driver = smtphosts = smtp.mailgun.orghosts_require_auth = smtp.mailgun.orghosts_require_tls = smtp.mailgun.org
Step 8. Save the new configuration.
Step 9. Send an email to see if the system works. The email header will include the “mailgun.” part.