Feb 012016

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:

  driver = dnslookup
  domains = example.com
  transport = remote_smtp 

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.