Educational ICT Virtualisation Specialist

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)8456 446 800 / +44 (0)1223 359900
E: enquiries@precedence.co.uk
Email-Routing

Jump To: Support > KB > NetManager > Email > Routing

Mail routing, i.e. sending mail for specific users and groups onto another server

Introduction

Normally, inbound mail will be delivered to local mailboxes after looking at aliases and distribution lists. If you want to send mail onto a different address (e.g. a home email address), you can use aliases for this (e.g. jsmith -> myhomeaddress@hotmail.com). The NetManager will pick the server to send this to either by looking at its MX records or by sending it onto the configured mail relay.

You can always check where and how mail will be delivered by using sendmail -bv. Here is an example when run on a mailserver which recognises thinit.net as a local domain. There is an alias set up for john -> jbloggs and another one for jbloggsnm -> jbloggs@netmanager.info:
1# sendmail -bv jbloggs
jbloggs... deliverable: mailer local, user jbloggs
2# sendmail -bv jbloggs@thinit.net
jbloggs@thinit.net... deliverable: mailer local, user jbloggs
3# sendmail -bv john@thinit.net
jbloggs... deliverable: mailer local, user jbloggs
4# sendmail -bv jbloggs@netmanager.info
jbloggs@netmanager.info... deliverable: mailer esmtp, host netmanager.info., user jbloggs@netmanager.info
5# sendmail -bv jbloggsnm
jbloggs@netmanager.info... deliverable: mailer esmtp, host netmanager.info., user jbloggs@netmanager.info
6# sendmail -bv jbloggsnm@thinit.net
jbloggs@netmanager.info... deliverable: mailer esmtp, host netmanager.info., user jbloggs@netmanager.info

mailer local means it will be delivered locally to a given user. mailer esmtp means it will be delivered directly to the mail servers for the given domain (in this case netmanager.info).

This is the same as using the Validate Address tab on E-Mail Administration > Send/Receive Validate Address in webadmin:

When you need routing

In the above examples, mail is either being delivered locally or being forwarded on with aliases. However, the action of forwarding on alters the destination email address (i.e. the original email address was jbloggsnm@thinit.net, but the new destination is jbloggs@netmanager.info). If the destination mail server is expecting the original address (i.e. jbloggsnm@thinit.net) you will have problems. You would hit against this if you were trying to set up a 2nd mail system to handle some addresses and not others (e.g. either on-site like Exchange or offsite like Office 365). Therefore if you want to keep email addresses the same when forwarding on, you will need mail routing.

Things like mail forwarding and mailertables (discussed below) act on all email received for a certain domain. If you only want to forward on mail for certain users (or groups), you will need mail routing.

When you do NOT need routing

  • If you simply want to forward ALL mail for your configured local domains to another server, set mail_forward to the name or IP address of that server
  • If you want to send all mail for a certain domain onto a specific server (e.g. if your mail relay has been blacklisted by a certain recipient, and you want to send directly to them):
    • Do not add the domain to the list of local domains
    • Enter a line like DOMAIN smtp:[hostname of mail server] in /etc/mail/mailertable
    • Rebuild mailertable database: cd /etc/mail && makemap hash mailertable < mailertable

Configuring routing

Firstly, enable the feature with mail_routing="y" in the settings file then running build_server to reconfigure the mail services. Next, configure your routing by adding lines to /etc/mail/routing. The format of each line is one of the following. These are in priority order, the top matches first:

  • recipient@domain SERVER
    - to match an email address exactly
  • recipient SERVER
    - where recipient is bit before @ in email address (not necessarily actual username), useful if you have multiple email domains
  • username SERVER
    - Looks up recipient part of email address in the list of aliases to get real username of recipient, i.e. if john is an alias for username jbloggs, having jbloggs will match both john and jbloggs
  • :groupname SERVER
    - Assumes recipient part of email address is a real username, matches the NetManager group that user is in
  • :aliasesgroup SERVER
    - as above, but matches group of resolved alias
  • @domain SERVER
    - all recipients at a given domain
  • * SERVER@@
    - a catch all

Use localhost as SERVER for the NetManager itself (i.e. deliver locally).

You do NOT need to run any build scripts after editing /etc/mail/routing,

Examples:

Nothing changes with the following routing file:
1# cat /etc/mail/routing
* localhost
2# sendmail -bv john@thinit.net
jbloggs@thinit.net... deliverable: mailer local, user jbloggs
By adding a match for the recipient part of the address, it will be matched exactly:
1# cat /etc/mail/routing
john otherserver
* localhost
2# sendmail -bv john@thinit.net
john@thinit.net... deliverable: mailer relay, host [otherserver.school.internal], user john@thinit.net
3# sendmail -bv jbloggs@thinit.net
jbloggs@thinit.net... deliverable: mailer local, user jbloggs
You could add rules for each alias (remember john is an alias for jbloggs), but by adding where the alias points to you can do it all in one line:
1# cat /etc/mail/routing
jbloggs otherserver
* localhost
2# sendmail -bv john@thinit.net
john@thinit.net... deliverable: mailer relay, host [otherserver.school.internal], user john@thinit.net
3# sendmail -bv jbloggs@thinit.net
jbloggs@thinit.net... deliverable: mailer relay, host [otherserver.school.internal], user jbloggs@thinit.net
User jbloggs is in the group called staff, so can use the group name too:
1# cat /etc/mail/routing
:staff otherserver
* localhost
2# groups jbloggs
staff
3# sendmail -bv john@thinit.net
john@thinit.net... deliverable: mailer relay, host [otherserver.school.internal], user john@thinit.net
© Copyright Precedence Technologies 1999-2024
Page last modified on August 16, 2016, at 10:39 AM by sborrill