Multidomain post system using IPS
I had such tasks:
- SMTP server (only imcoming) serving many domains and users.
- POP3 server for a lot of users and domains, with identical names in different domains (e.g. firstname.lastname@example.org and email@example.com).
- All this should use a single IP address.
- Special "domain accounts" should exist: if specified user is not found, but such domain exists, all mail should fall to this special account. And it is necessary only for some domains.
- Addition of domains and users should not require server restart and should be automated simply.
- The solution should have text configs (see 4) and do not require PM (I administrate this server via ssh only)
- Some domains are aliases (for example alias.com and domain1.com).
I advise you to use latest IPS version for this solution. You can read in the documentation how to configure it, and I shall speak only about adjustments specific to our task. The section [SMTP-1] in my config file contains such settings:
[SMTP-1] Address=188.8.131.52 # my ip address Protocol=smtpd ClientAddress=* Host=smtp ForwardAddress= ForwardToServer= QueueDirectory=.\queue\mail LocalDomain=localhost # You need to specify ONLY localhost here. LocalDomains=@localhost @[127.0.0.1] hookOnCommand=.\scripts\smtp\rxOnCommand.rexx # our rexx script.From mentioned above follows that IPS thinks that it serves ONLY 1 domain, and IPS starts a script rxOnCommand.rexx on every command. The second part of my article describes the work of the given script.
What this script does.
- Intercepts line RCPT TO: and also parses e-mail to domain and user name. Checks established aliases and replaces them with the main domain (see a line after /* alias1 */).
- Reads a file specified in a variable domain_file (a text file containing list of local domains, line=domain) and checks out if our domain exist. If domain is not present, it returns a line without changes (then IPS will answer that forward not allowed).
- If it is our domain we search for the user like user%domain (e.g.
samm%domain1.com). If such user is found, we return to ips string like
"RCPT TO: <user%domain@localhost>"(in our example - RCPT TO: <samm%domain1.com@localhost>). If user is not found, script will return string like "RCPT TO: <domain@localhost>"(in our example - RCPT TO: <domain1.com@localhost>).
- Install IPS and adjust section [SMTP-1] according to my recommendations.
- Copy a script in IPS\scripts\smtp\rxOnCommand.rexx.
- Edit variable domain_file in rxOnCommand.rexx to specify a file where you plan to place the list of domains. Create this file and place to it all of your domains and aliases (string=domain).
- write all your aliases (if they exist) after line /* alias */ in
rxOnCommand.rexx in the followinf way:
if domain ='alias.com' then domain ='primary.com' /* alias */
- If we want to create the user who will receive only messages addressed to him (e.g. firstname.lastname@example.org) create the user with a name like user%domain (in our case samm%domain1.com). Now all messages addressed to him will be placed to his mailbox. His pop3 login will look like user%domain (in our example -- samm%domain1.com).
- If we want to create the user receiving a mail on all domain (in a case if user-addressee is not found) it is necessary to create a user whose name is equal to domain name (for example, domain1.com). His pop3 login will be domain (in our case domain1.com). That's all.
Alex Samorukov (Samm)