Custom Email Routing Print

  • 0

Sometimes we come across issues where emails sent from our server/network unable to reach certain destinations due to network issues, blocklists, etc.

For a quick workaround, we have prepared a backup SMTP relay service in rdns2.nocser.net (sitting on a different network @ US, and only allows relaying from our networks). To make use of this backup SMTP relay service for certain destinations, change your Exim configuration as follows:-

1. SSH into the affected server.

2. Backup exim configuration:-
# cd /etc
# cp -avi exim.conf exim.con.no-smarthost

3. Edit exim configuration and add the custom routing rule (example: if the-recipient-domain.com is blocking your server's email):-
# vim exim.conf

- Look for 'begin routers' section, and add the following:-

# Domain-based routing, based on smart host docs
# Ref: http://help.comodo.com/topic-157-1-288-4546-.html
# Ref: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-some_common_configuration_settings.html#SECTvirtualdomains
rdns2_smarthost_router:
driver = manualroute
domains = the-recipient-domain.com
ignore_target_hosts = 127.0.0.0/8
transport = rdns2_smarthost_transport
route_list = $domain rdns2.nocser.net::25
no_more

- Look for 'begin transports' section, and add the following:-

rdns2_smarthost_transport:
driver = smtp

- Save the file.
:wq

4. Restart exim:-
# /etc/init.d/exim restart

5. Send a test e-mail from your server to the recipient address which blocked the mail previously. Verify in exim logs that it relays through the backup SMTP relay host:-
# tail -f /var/log/exim_mainlog
....

2014-02-25 11:50:44 1WI92Y-0001YS-2L <= you@your-server.com H=(YourPC) [175.137.190.18]:49265 P=esmtpa A=dovecot_login:you@your-server.com S=92064 id=50B3B81721DA47D997291F75CACE4CF1@YourPC T="Test E-Mail" for person@the-recipient-domain.com
2014-02-25 11:50:44 cwd=/var/spool/exim 3 args: /usr/sbin/exim -Mc 1WI92Y-0001YS-2L
2014-02-25 11:50:50 1WI92Y-0001YS-2L => person@the-recipient-domain.com R=rdns2_smarthost_router T=rdns2_smarthost_transport H=rdns2.nocser.net [74.63.105.165] C="250 2.0.0 Ok: queued as 1D2B4CF8767"
2014-02-25 11:50:50 1WI92Y-0001YS-2L Completed

- As you can see in the example above, the e-mail will be routed through the backup SMTP relay (rdns2.nocser.net [74.63.105.165]) instead of directly to the-recipient-domain.com's mail server.

6. Verify the email is delivered by logging in to the backup relay server and look for the Queue ID mentioned as "queued as" in the logs (in above example, the queue ID to look for is 1D2B4CF8767).
- SSH rdns2.nocser.net (ref: tech)
# grep 1D2B4CF8767 /var/log/all.log

all.log.1:Feb 25 07:02:18 rdns2 postfix/smtpd[30535]: 1D2B4CF8767: client=your-server.com[42.0.28.x]
all.log.1:Feb 25 07:02:18 rdns2 postfix/cleanup[30538]: 1D2B4CF8767: message-id=<50B3B81721DA47D997291F75CACE4CF1@YourPC>
all.log.1:Feb 25 07:02:20 rdns2 postfix/qmgr[8095]: 1D2B4CF8767: from=<you@your-server.com>, size=94438, nrcpt=3 (queue active)
all.log.1:Feb 25 07:02:32 rdns2 postfix/smtp[30539]: 1D2B4CF8767: to=<person@the-recipient-domain.com>, relay=the-recipient-domain[11x.9x.13x.14x]:25, delay=15, delays=2/0.08/2.6/9.9, dsn=2.0.0, status=sent (250 OK id=1WI9Ji-002oX8-FV)
all.log.1:Feb 25 07:02:32 rdns2 postfix/qmgr[8095]: 1D2B4CF8767: removed

- which shows that it delivered successfully to the-recipient-domain.com's server.

References:-
http://help.comodo.com/topic-157-1-288-4546-.html
http://www.exim.org/exim-html-current/doc/html/spec_html/ch-some_common_configuration_settings.html#SECTvirtualdomains

Was this answer helpful?

« Back