Content is scrollable
Back to May 2000 meeting page
Talk for Manchester LUG
Matthew John Palmer
Mail configuration is a frequent stumbling block for new net admins. Not simply because the concept is hard - mail is easy, after all - but the myriad little options is the fun part.
Sendmail allows you to do it all. As such, it can seem dense and complicated. A foe. However, if we concentrate on small sections at a time, and 'divide and conquer', we can turn sendmail into our best friend.
The config options presented here will work for 8.10 and later, guaranteed. They may work for 8.9 or earlier, but I'd recommend 8.10.
MUA -> MTA -> (Internet) -> MTA -> MUA
To show the power (if not abject simplicity) of Sendmail, here are a couple of sample configurations doing strange and ungainly things with mail. Feel free to use them in your own mail systems.
We're assuming some things:
From these assumptions, the following config will be used:
dnl # Set OS type to foobar - you should probably change this! OSTYPE(`foobar')dnl dnl # Since we're not on the Internet permenantly, don't try and lookup dnl # foreign names immediately. FEATURE(`nocanonify')dnl dnl # Forward all mail (with no exceptions) to `mail.domain.fake.uk' FEATURE(`nullclient', `mail.domain.fake.uk')dnl
dnl # Set OS type to foobar - you'll need to change this! OSTYPE(`foobar')dnl dnl # Do not transport via 'expensive' (as determined by the 'e' flag) dnl # mailers upon initial submission. define(`confCON_EXPENSIVE', `True')dnl dnl # Make the SMTP protocol (which we will use to deliver any mail not for dnl # the local system) an 'expensive' mailer (see above) define(`SMTP_MAILER_FLAGS', `+e')dnl dnl # Stop putting our hostname on mail and just put 'domain.fake.uk' by default define(`confDOMAIN_NAME', `domain.fake.uk')dnl dnl # Not permenantly connected to the net, so don't go looking up names all dnl # the time. FEATURE(`nocanonify')dnl dnl # Add `domain.fake.uk' to class 'm' - used for *everything* rewrite related MASQUERADE_DOMAIN(`domain.fake.uk')dnl dnl # Add our domain name (from confDOMAIN_NAME) to any and all mail without it FEATURE(`always_add_domain')dnl dnl # Rewrite both header and envelope of the mail message. FEATURE(`masquerade_envelope')dnl dnl # File containing all of the domains we will accept mail for define(`confCW_FILE', `/etc/mail/sendmail.cw')dnl dnl # Relay anything in the domain `domain.fake.uk' but not anything else. RELAY_DOMAIN(`domain.fake.uk')dnl dnl # Address translation for outgoing mail, with the hash database located dnl # in /etc/mail/outgoing.trans.db FEATURE(`genericstable', `hash /etc/mail/outgoing.trans.db')dnl dnl # Apply translation to anything in `domain.fake.uk' GENERICS_DOMAIN(`domain.fake.uk')dnl FEATURE(`generics_entire_domain')dnl dnl # The mailers we want to support MAILER(`local')dnl MAILER(`smtp')dnl
bob user1@mailhost.com fred user2@freemail.com jane user3@foo.org
localhost domain.fake.uk
SENDMAIL_CF_M4=/usr/share/sendmail/sendmail.cf/m4/cf.m4 all: outgoing.trans.db sendmail.cf outgoing.trans.db: outgoing.trans.txt cp outgoing.trans.db outgoing.trans.db.old makemap hash outgoing.trans.db < outgoing.trans.txt sendmail.cf: sendmail.mc cp sendmail.cf sendmail.cf.old m4 $(SENDMAIL_CF_M4) sendmail.mc > sendmail.cf
A sneaky way of doing things which only works if your mailbox provider will handle it. Check if they preserve 'detail' specifiers (username+detail form).
OSTYPE(`foobar')dnl define(`confCON_EXPENSIVE', `True')dnl define(`SMTP_MAILER_FLAGS', `+e')dnl FEATURE(`nocanonify')dnl dnl # Class m additions MASQUERADE_DOMAIN(`domain.fake.uk')dnl FEATURE(`masquerade_entire_domain')dnl dnl # Hosts we will accept mail for define(`confCW_FILE', `/etc/mail/sendmail.cw')dnl dnl # Address translation for outgoing mail, with the hash database located dnl # in /etc/mail/outgoing.trans.db FEATURE(`genericstable', `hash /etc/mail/outgoing.trans.db')dnl dnl # Translate incoming mail FEATURE(`virtusertable', `hash /etc/mail/incoming.trans.db')dnl MAILER(`local')dnl MAILER(`smtp')dnl
@domain.fake.uk realuser+%1@yourisp.com
realuser+*@yourisp.com %2@domain.fake.uk
SENDMAIL_CF_M4=/usr/share/sendmail/sendmail.cf/m4/cf.m4 all: outgoing.trans.db incoming.trans.db sendmail.cf outgoing.trans.db: outgoing.trans.txt cp outgoing.trans.db outgoing.trans.db.old makemap hash outgoing.trans.db < outgoing.trans.txt incoming.trans.db: incoming.trans.txt cp incoming.trans.db incoming.trans.db.old makemap hash incoming.trans.db < incoming.trans.txt sendmail.cf: sendmail.mc cp sendmail.cf sendmail.cf.old m4 $(SENDMAIL_CF_M4) sendmail.mc > sendmail.cf
Since somebody asked especially for them, here is a mail config which will do multiple virtual domains, with all domains specified in the file /etc/mail/virtdomains. All mail for each domain will get forwarded to a mailbox called <domain>+<user>@realmail.com, and the inverse will also happen (mail from foo+fred@realmail.com will go out as being from fred@foo.com)
There are three domains we're hosting:
I am assuming that we have a fulltime, fully DNSd link to the Internet at large.
As as aside, this setup, as is, is untested, but it should work without a hassle.
OSTYPE(`foobar')dnl dnl # Domains which we handle mail for USE_CW_FILE(`/etc/mail/virtdomains')dnl dnl # Domains we will relay from and to RELAY_DOMAIN_FILE(`/etc/mail/virtdomains')dnl dnl # Outgoing translation table FEATURE(`generics_table', `hash /etc/mail/outgoing.trans.db')dnl GENERICS_DOMAIN_FILE(`/etc/mail/virtdomains')dnl FEATURE(`generics_entire_domain')dnl dnl # Incoming translation table FEATURE(`virtuser_table', `hash /etc/mail/incoming.trans.db')dnl VIRTUSER_DOMAIN_FILE(`/etc/mail/virtdomains')dnl FEATURE(`virtuser_entire_domain')dnl
/etc/mail/virtdomains will look like:
foo.com bar.org wombat.net
A sample /etc/mail/outgoing.trans.txt:
foo+*@realmail.com %1@foo.com bar+*@realmail.com %1@bar.org wombat+*@realmail.com %1@wombat.net
Also, we will translate coming back, specified in /etc/mail/incoming.trans.txt:
@foo.com foo+%1@realmail.com @bar.org bar+%1@realmail.com @wombat.net wombat+%1@realmail.com
Finally, an /etc/mail/Makefile to hold it all together:
SENDMAIL_CF_M4=/usr/share/sendmail/sendmail.cf/m4/cf.m4 all: outgoing.trans.db incoming.trans.db sendmail.cf outgoing.trans.db: outgoing.trans.txt cp outgoing.trans.db outgoing.trans.db.old makemap hash outgoing.trans.db < outgoing.trans.txt incoming.trans.db: incoming.trans.txt cp incoming.trans.db incoming.trans.db.old makemap hash incoming.trans.db < incoming.trans.txt sendmail.cf: sendmail.mc cp sendmail.cf sendmail.cf.old m4 $(SENDMAIL_CF_M4) sendmail.mc > sendmail.cf