I recently configured my cPanel/Exim installation to relay mail through SendGrid, using SendGrid’s official documentation and this page to supplement it.
After some tweaking, everything worked as expected, but I was left with one problem: I have scripted emails that include some large (>20 MB) attachments, and SendGrid does not support attachments of that size.
These emails are sent to a single domain, and I have no issue sending them directly, so I configured Exim (through WHM’s Service Configuration -> Exim Configuration Manager -> Advanced Editor) to send messages to that one domain without going through the SMTP relay, while keeping the relay as the default mail transport.
To do this, edit the PREROUTERS section of your Exim configuration file. Before the relay transport block, typically “send_via_sendgrid” for SendGrid, insert the following lines:
to_example: driver = dnslookup domains = example.com transport = remote_smtp no_more
You’ll want to update the router name (“to_example”) and the domain to suit your needs. It is very important to place this above the SendGrid router block, because order matters! This code tells Exim that if the message is destined for “example.com”, that it should utilize the “remote_smtp” transport.
Any domains that don’t match this rule will continue down to the SendGrid transport code, so they will relay as expected.