Technical Notes

Routing Mail To Other Local Systems

Problem Description

We want to have all mail into our site addressed as user@domain.com. Most of our mail users are on one kind of email package but a few use a different one. The problem is , if I want mail to arrive this way I have to know which user lives where... I'd prefer not do this sort of maintenance. Is there some generic/wild card entry that you put in the pmdf configuration files that will do this separation automagically?

Clues to Solving the Problem

  • Routing of mail through PMDF is based primarily on the domain name of the destination. Rewrite rules are used to make these routing decisions.
  • While rewrite rules work on the domain name only, they can call out to mechanisms that work on the username part of an address.
  • The PMDF GENERAL DATABASE and the PMDF DIRECTORY CHANNEL are mechanisms that have the capability to work on the username part of an address.
  • Rewrite rules can be direction specific and can be constructed to work on the either the envelope or the headers of a message or both.
  • Multiple rewrite rules for a single domain can be setup in series in order to have the different behaviors based on which address is being worked on.
  • A REVERSE mapping table can be used to transform all outgoing addresses into user@domain.com.

Solution

Do the username lookup against the smaller population of users. This can be done either of two ways:-

  1. Rewrite rules that refer to a DIRECTORY CHANNEL pseudo domain.
                                   -  OR -
  2. Rewrite rules calling out to a PMDF GENERAL DATABASE.

A couple of site supplied files are required. If these files don't exist one should create them. The first file is a world readable mapping file. The name of this file is pmdf_table:mappings. or /pmdf/table/mappings . The second file is a world readable option file. The name of this file is /pmdf/table/option.dat or pmdf_table:option.dat.

Our sample site, Sample Inc., uses PMDF-MTA and PMDF-LAN to gateway internet mail for its 3500 cc:Mail users , and about 40 or so local mail accounts. All mail comes to their site addressed to User@domain.com.

PMDF is already configured and running on the node MAIL, and mail is transferred to the main cc:Mail machine NODEB. A quick inspection of their configuration files shows that the hostname on the second line of the l channel definition is mail.domain.com. The hostname on the second line of the cc_local channel definition says nodeb.domain.com.

Three domain names are therefore involved: the canonical name domain.com, the name on the local channel mail.domain.com and the domain name assigned to the other email gateway nodeb.domain.com.

Method 1: The Directory Channel

  1. Set up DNS entries so that the canonical domain name points to the PMDF-MTA using a MX record. Using a tool like nslookup one would see:-
    $ nslookup /type=mx domain.com
    
    Server:  THEOREM.DOMAIN.COM
    Address:  10.0.0.4
    
    DOMAIN.COM preference = 10, mail exchanger = MAIL.DOMAIN.COM
    DOMAIN.COM preference = 99, mail exchanger = THEOREM.DOMAIN.COM
    DOMAIN.COM nameserver = THEOREM.DOMAIN.COM
    MAIL.DOMAIN.COM  internet address = 10.0.0.2
    THEOREM.DOMAIN.COM       internet address = 10.0.0.4
    
    
  2. Create the directory to hold the database files.
    On VMS
    
    • $ CREATE/DIR PMDF_ROOT:[directories]/OWNER=[SYSTEM]
    On UNIX
    • # mkdir -mu=rwx,go= /pmdf/directories
    • # chown pmdf:bin /pmdf/directories
  3. Create a file called sample_com.txt and populate it with usernames from the mail system with the lowest concentration of users:-
      
    ! sample_com.txt - source file for the directory channel pseudo domain 
    ! DOMAIN.COM. 
    !
    !Entries to direct mail for postmaster to the local system  
    !  
    postmast               idest@mail.domain.com  
    postmaster             idest@mail.domain.com  
    webmaster              webmaster@mail.domain.com
    root                   idest@mail.domain.com  
    !  
    ! The few proud users who get mail on this system  
    !  
    BonaFide               bonafide@mail.domain.com  
      .                             .  
      .                             .  
    LoremIpsum             loremipsum@mail.domain.com  
      .                             .  
      .                             .  
    CaveatEmptor           caveatemptor@mail.domain.com  
    !  
    !  Entries for mailing lists so we can address them as   
    !  list-name@domain.com from  
    !  
    proofs-discussion      proofs@mail.domain.com  
    !  
    ! Default redirection - pass all mail over to the NODEB.DOMAIN.COM   
    ! domain.  
    !
    *                      *@NODEB.DOMAIN.COM  
    !  
    [End of file]
    
    
  4. Create the directory channel database.
    On VMS
    
    • $ pmdf crdb sample_com.txt PMDF_ROOT:[directories]sample_com.dat_temp
    • $ rename PMDF_ROOT:[directories]sample_com.dat_temp PMDF_ROOT:[directories]sample$com.dat
    On Unix
    
    • # pmdf crdb sample_com.txt /pmdf/directories/d_com.dat_temp
    • # pmdf renamedb /pmdf/directories/d_com.dat_temp /pmdf/directories/domain.com
    • # chown -R pmdf:bin /pmdf/direcrories
  5. Edit the pmdf configuration file and add the directory channel in the channel block section.
      
    !  
    ! The directory channel  
    !  
    
    directory  
    DIRECTORY-DAEMON  
      
    ! 
    
  6. Add a rewrite rule for the canonical domain name to call out to the directory channel. This is placed near the top of the pmdf.cnf file.
      
    !  
    ! Rewrite rules for domain.com top level domain  
    !  
    DOMAIN.COM             $U%DOMAIN.COM@DIRECTORY-DAEMON  
    !  
    ! Rewrite rule for the local host  
    !  
    MAIL                   $U@MAIL.DOMAIN.COM  
    MAIL.DOMAIN.COM        $U@MAIL.DOMAIN.COM  
    ! 
    
    
  7. Place a REVERSE table in the mapping file.
    !  
    REVERSE  
      
      *@*.DOMAIN.COM       $0@DOMAIN.COM$Y$D 
    !  
    

  8. Insert the entry below in the pmdf option file:
    !
    USE_REVERSE_DATABASE=5 
    !
    ! Note:In PMDF V5.1, USE_REVERSE_DATABASE=5 is the default
    !
    
    
  9. The rewrite rules and channel definitions for the mail system with the highest concentration of users remain the same:-
    ! LAN.RULES - PMDF-LAN rewrite rules
    ! Written by Peter Stone, 1-AUG-1996 1:09
    ! This file was created by the PMDF-LAN configuration generator V5.0.
    !
    nodeb                  $U%nodeb.domain.com
    nodeb.domain.com       $U@nodeb.domain.com
    !
    [End of file]
    
    
    
    ! LAN.CHANS - PMDF-LAN channel definitions
    ! Written by Edward Guardian, 1-AUG-1996 1:09
    ! This file was created by the PMDF-LAN configuration generator V5.0.
    
    cc_local
    nodeb.domain.com
    
    !
    [End of file]
    

Method 2: The General Database

  1. Set up DNS entries so that the canonical domain name points to the PMDF-MTA using a MX record. Using a tool like nslookup one would see:-
    $ nslookup /type=mx domain.com
    
    Server:  THEOREM.DOMAIN.COM
    Address:  10.0.0.4
    
    DOMAIN.COM       preference = 10, mail exchanger = MAIL.DOMAIN.COM
    DOMAIN.COM       preference = 99, mail exchanger = THEOREM.DOMAIN.COM
    DOMAIN.COM       nameserver = THEOREM.DOMAIN.COM
    MAIL.DOMAIN.COM  internet address = 10.0.0.2
    THEOREM.DOMAIN.COM       internet address = 10.0.0.4
    
    
  2. Create the file general.txt and populate it with the usernames from the mail system with the lowest concentration of users. Demonstrandum has :-
    ! General.txt - Source file for the general database 
    ! for the domain.com domain.  
    ! NOTE: The percent signs (%) in this file are intentional !  
    !  
    ! Entries to direct mail for postmaster to the local system 
    !  
    postmast               idest%mail.domain.com 
    postmaster             idest%mail.domain.com 
    webmaster              webmaster%mail.domain.com
    root                   idest%mail.domain.com
    !  
    ! The few proud users who get mail on this Node 
    !
    BonaFide               bonafide%mail.domain.com
      .                             .  
      .                             .  
    LoremIpsum             loremipsum%mail.domain.com  
      .                             .  
      .                             .  
    CaveatEmptor           caveatemptor%mail.domain.com  
    !  
    !  Entries for mailing lists so we can address them as   
    !  list-name@domain.com.  Mailing list aliases are
    !  fully defined in the alias file.
    !   
    !  
    proofs-discussion      proofs%mail.domain.com  
    !  
    [End of file]
    
    
  3. Create the general database

    On VMS

    $ pmdf crdb general.txt pmdf_table:general.tmp
    $ rename pmdf_table:general.tmp PMDF_GENERAL_DATABASE
    

    On Unix

    # pmdf crdb general.txt /pmdf/table/generaldb-tmp
    # pmdf renamedb /pmdf/table/generaldb-tmp PMDF_GENERAL_DATABASE
    # chown pmdf:bin /pmdf/table/generaldb.*
    

  4. Add rewrite rules for the canonical domain name to call out to the general database. This is placed near the top of the pmdf.cnf file.
      
    !  
    ! Rewrite rules for domain.com top level domain
    !  
    DOMAIN.COM             $($U)$E$F  
    DOMAIN.COM             $U%NODEB.DOMAIN.COM$E$F  
    !    
    ! First rewrite above calls out to general database. 
    ! Second rewrite is for roll over to the nodeb.domain.com domain  
    !  
    ! Rewrite rule for the local host  
    !  
    MAIL                   $U@MAIL.DOMAIN.COM  
    MAIL.DOMAIN.COM        $U@MAIL.DOMAIN.COM  
    !
    
    
  5. Place a REVERSE table in the pmdf mapping file.
      
    !
      
    REVERSE  
      
      *@*.DOMAIN.COM       $0@DOMAIN.COM$Y$D 
    !
    
    
  6. Insert the entry below in the pmdf option file:
    !
    USE_REVERSE_DATABASE=5 
    !
    ! Note:In PMDF V5.1, USE_REVERSE_DATABASE=5 is the default
    !
    
  7. The rewrite rules and channel definitions for the mail system with the highest concentration of users remain the same. For domain.com this corresponds to the cc:Mail users. As such their LAN.CHANS and LAN.RULES files, shown below for completeness, are untouched.:-
    ! LAN.RULES - PMDF-LAN rewrite rules
    ! Written by Smar Talek, 1-AUG-1996 1:09
    ! This file was created by the PMDF-LAN configuration generator V5.0.
    !
    nodeb                   $U%nodeb.domain.com
    nodeb.domain.com        $U@nodeb.domain.com
    !
    [End of file]
    
    
    
    ! LAN.CHANS - PMDF-LAN channel definitions
    ! Written by Ryddi Kulos, 1-AUG-1996 1:09
    ! This file was created by the PMDF-LAN configuration generator V5.0.
    
    cc_local
    nodeb.domain.com
    
    !
    [End of file]
    

How it Works

Mail addressed to LoremIpsum@domain.com hits the first rewrite rule. With method 2 this triggers a lookup in the general database. A match is found and mail is redirected to loremipsum%mail.domain.com. With method 1 the message is first queued to the directory channel which runs and does a lookup in the directory channel database. A match is found and mail is redirected to lipsum@mail.domain.com. The name mail.domain.com belongs to the "l" channel therefore the message is delivered locally.

Mail addressed to DolorSitamet@domain.com is also passed to a database lookup via one of the mechanisms above. With method 1 there is no match for DolorSitamet in the general database so the first rewrite rule fails and PMDF continues scanning the rest of the rewrite rules for a match on the domain name.. The second rewrite rule does match ands acts as the "roll over" or "fall through" case. The domain name part gets rewritten and mail is directed to DolorSitamet@nodeb.domain.com.

With method 2, there is no match for Dolor.Sitamet in the directory channel database so the "*" entry applies, which results in the mail being requeued for the channel that handles the nodeb.domain.com domain. The name nodeb.domain.com belongs to the "cc_local" channel, and so the message is handed over to cc:Mail.

All outgoing mail is REVERSE mapped back to display a From: address of user@domain.com, and the USE_REVERSE_DATABASE option specifies that addresses on the cc: header lines are reverse mapped as well.

Pros & Cons

General database Directory channel
The callout to the general database does the final rewrite "inline" (on-the-fly) and is a one step process.
The message is first written to the directory channel after which the channel runs and does the username lookup.

The final format of an address passed to the general database can easily be checked by the test rewrite utility.

The final form of the address passed to the directory channel is not available to the test rewrite utility.

Some may find the callout to the general database mysterious when scanning through the rewrite rules. Many find the directory channel more intuitive when scanning through the rewrite rules.

Additional Notes

This solution relies on the username part being unchanged. i.e. joe@domain.com has a mailbox joe in cc:Mail or ALLin1.

Search About Contact Home Search About Contact Home