Routing outgoing emails

gesman

Registered
May 7, 2013
4
0
1
cPanel Access Level
Root Administrator
Hello,

I own dedicated server: Centos 6 + WHM where i host multiple sites. Many emails are just forwarded to related gmail accounts, such as:
[email protected] -> [email protected]
[email protected] -> [email protected]

I want to route all outgoing emails (initiated via scripts on my sites, such as contact forms or password reset forms) via SendGrid/SMTP. Although I *do NOT* want to route all incoming emails (mostly incoming spam) via SendGrid.

I followed this tutorial: /http://sendgrid.com/docs/Integrate/Mail_Servers/exim.html.
But as a result of it - I have *ALL* emails (incoming and outgoing) going through SendGrid:
- Gmail is forwarding emails from paypal.com to spam folder.
- Every piece of spam is consuming my SendGrid quota now.

What do I need to change to make sure that only outgoing emails initiated by my websites go through SendGrid?

Gleb
 
Last edited:

gesman

Registered
May 7, 2013
4
0
1
cPanel Access Level
Root Administrator
Ok, here's an answer. Took me 24 hours to dig for it.
Put this into:
WHM >> Home >> Service Configuration >> Exim Configuration Manager >> Advanced Editor
"Section: ROUTERSTART" :
Code:
send_via_sendgrid:
  driver = manualroute
  domains = ! +local_domains
  condition = ${if match_domain{$sender_address_domain}\
                 {$primary_hostname : +local_domains}\
                 {yes}{no}}
  transport = sendgrid_smtp
  route_list = "* smtp.sendgrid.net::587 byname"
  host_find_failed = defer
  no_more
This will allow you to use SendGrid only for outgoing emails originated by your website scripts, but *skip sendgrid* for all incoming emails, including emails that require subsequent forwarding outside.
Thus saving your Sendgrid quota and essentially allowing you escape dedicated server IP blacklisting/whitelisting cat-n-mouse games.

Here's what above will allow you to have:


1. Sending email to outside from any domain on your dedicated server to be routed through Sendgrid:
[email protected] --[SENDGRID SMTP]--> [email protected]

2. Contact forms and scripts from your websites will route all emails through sendgrid:
[email protected] --[SENDGRID SMTP]--> [email protected]

3. Incoming, pre-authenticated (and spam) emails processed directly, without sendgrid:
[email protected] -> [email protected] ---/*NO SENDGRID HERE*/--> [email protected]
[email protected] -> [email protected] ---/*NO SENDGRID HERE*/--> [email protected]

In latter(spam) case - email might not even reach destination due to anti-spam measures.

PS: You of course may use any other transactional email delivery service, not only SendGrid. Just change SMTP server address and credentials.

Gleb
 
Last edited:

zeta1600

Member
Mar 25, 2011
11
0
51
This was about the best help on this issue I've found. I was wondering if you would be willing to give a step by step to implement sendgrid. Like, I don't understand how and where to add things according to this page: https://sendgrid.com/docs/Integrate/Mail_Servers/exim.html
How and where to add this?
begin authenticators

sendgrid_login:
driver = plaintext
public_name = LOGIN
client_send = : [email protected] : YourSendGridPassword
Also, it says: Add a route in the Router Configuration Box:? Which router box? ROUTERSTART, like your instruction above?
And, it says: Add a transport to the Transport Configuration Box:? Which Transport box? TRANSPORTSTART?

Any help would be greatly appreciated.
 

zeta1600

Member
Mar 25, 2011
11
0
51
I got this to work... the first time I edited the file at WHM >> Home >> Service Configuration >> Exim Configuration Manager >> Advanced Editor, it created the file /etc/exim.conf.local. I then just edited the file to follow the instructions at: https://sendgrid.com/docs/Integrate/Mail_Servers/exim.html#-cPanel. You should begin there.

I went to Edit MX Entry and added smtp.sendgrid.net has priority 0.

This tutorial helped: Tutorial Of Administrator: Implementing SendGrid with Exim on cPanel

I hope this helps someone.