William Shallum

Sendmail: redirect all mail for development

Posted Jul 24 2010, 06:56 by William Shallum [updated Sep 4 2010, 12:04]

Problem

The development server should not really send mail to addresses. The emails from the dev server should be gathered in a nice, central location so the developers can look at it.

Solution

If you’re using sendmail, add to sendmail.mc:

LOCAL_RULE_0
R$*     $#local $:william

The space between R$* and $# is a TAB character. You must use a tab character (ASCII 9) here.

Don’t forget to regenerate the sendmail.cf file (i.e. run make) and reload the configuration (/etc/init.d/sendmail reload).

The above will redirect all mail to the local account william. The headers (From and To) all stay intact. For SMTP mailers, this will only change the recipient address in the envelope, not the address in the headers.

To redirect to an SMTP mailer, use:

LOCAL_RULE_0
R$*    $#smtp $@example.com $:someone

That will send all emails to someone@example.com.

To test, you can use sendmail -bt:

$ sendmail -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
> 3,0 someuser@example.com
canonify           input: someuser @ example . com
Canonify2          input: someuser < @ example . com >
Canonify2        returns: someuser < @ example . com . >
canonify         returns: someuser < @ example . com . >
parse              input: someuser < @ example . com . >
Parse0             input: someuser < @ example . com . >
Parse0           returns: someuser < @ example . com . >
ParseLocal         input: someuser < @ example . com . >
ParseLocal       returns: $# local $: william
parse            returns: $# local $: william

Note that this will also redirect emails for local users, which may not be what you want:

> 3,0 root
canonify           input: root
Canonify2          input: root
Canonify2        returns: root
canonify         returns: root
parse              input: root
Parse0             input: root
Parse0           returns: root
ParseLocal         input: root
ParseLocal       returns: $# local $: william
parse            returns: $# local $: william

For more information

Please consult the Sendmail Installation and Operation Guide for more information on the exact syntax of rewrite rules, and what the different rulesets do.