Linux Sendmail+Dialup mini-HOWTO <author>Leif Erlingsson <tt/<leif@lege.com>/, Jan P Tietze <tt/<jptietze@mail.hh.provi.de>/, Vincent Zweije <tt/<zweije@xs4all.nl>/ <date>v1.00, 4 July 1998, sendmail 8.8.8 <abstract> This mini HOWTO describes some basic configurations that are necessary to make sendmail work comfortably in the typical at-home situation: a single machine with a dialup connection to Internet. The most important features described are (1) queuing remote mail while local mail is delivered immediately, (2) preventing sendmail from causing spurious triggering of the dialup connection, and (3) providing automatic address translation on all outgoing mail. </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <sect> <!-- 1 --> Introduction <p> This document used to be named the Linux Mail-Queue mini-HOWTO, the earlier version being Queue-R-Mail.v2.02.{sgml,txt,*.html}. <p> The document is written by three authors. The NON dial-on-demand solutions part (oldest part) is written by Leif Erlingsson <leif@lege.com>, and the newer dial-on-demand solutions part is written by Jan P Tietze <jptietze@mail.hh.provi.de>. The address translation part has been written by Vincent Zweije <zweije@xs4all.nl>. <sect> <!-- 2 --> NON dial-on-demand solutions PART <p> Written by Leif Erlingsson <leif@lege.com>. The original version of this part contained a lot of unnecessary stuff. This is all it takes, really... <sect1> <!-- 2.1 --> Starting sendmail <p> Slackware et al: /etc/rc.d/rc.M: <tscreen><verb> echo &dquot;Starting sendmail daemon (/usr/sbin/sendmail -bd -os) [queue only mode]...&dquot; /usr/sbin/sendmail -bd -os # NOT &dquot;-bd -q 15m&dquot;, the &dquot;standard&dquot; flags! </verb></tscreen> RedHat et al: /etc/rc.d/init.d/sendmail.init: <tscreen><verb> echo -n &dquot;Starting sendmail: [queue only mode]&dquot; daemon sendmail -bd -os # NOT daemon sendmail -bd -q1h </verb></tscreen> The -os is not really essential, all it does is this: <tscreen><verb> SuperSafe [s] Be super-safe when running things, i.e., always instantiate the queue file, even if you are going to attempt immediate delivery. Sendmail always instantiates the queue file before returning control the client under any circumstances. This should really always be set. </verb></tscreen> This should already be configured in the default sendmail.cf anyway. <sect1> <!-- 2.2 --> Configuring sendmail <p> Serious sendmail users use the m4 source for this. I recommend this solution if you ever plan on upgrading sendmail and also make anything but trivial changes to sendmail.cf. If you never intend to fix sendmail so envelope return headers et al works even though you might be on dynamic dial in IP or something, then you may not need to get the m4 source. <sect2> <!-- 2.2.1 --> Configuring sendmail.cf directly, for trivial configurations <p> This way of doing things is extremeley version dependent vs. sendmail.cf versions. The following solution is *only* valid for sendmail-8.8.x. Edit /etc/sendmail.cf: <tscreen><verb> # avoid connecting to &dquot;expensive&dquot; mailers on initial submission? O HoldExpensive=True </verb></tscreen> ... later ... <tscreen><verb> ##### @(#)smtp.m4 8.33 (Berkeley) 7/9/96 ##### Msmtp, P=[IPC], F=mDFMuXe, S=11/31, R=21, E=\r\n, L=990, T=DNS/RFC822/SMTP, A=IPC $h Mesmtp, P=[IPC], F=mDFMuXae, S=11/31, R=21, E=\r\n, L=990, T=DNS/RFC822/SMTP, A=IPC $h Msmtp8, P=[IPC], F=mDFMuX8e, S=11/31, R=21, E=\r\n, L=990, T=DNS/RFC822/SMTP, A=IPC $h Mrelay, P=[IPC], F=mDFMuXa8e, S=11/31, R=61, E=\r\n, L=2040, T=DNS/RFC822/SMTP, A=IPC $h </verb></tscreen> The important flag above is ``e''. Don't fuss if the other flags look different in your file. Keep your flags as-is, only add ``e'' to your flags according to the above examples, unless it's there already. ``e'' marks the mailers as ``expensive''. <sect2> <!-- 2.2.2 --> Configuring sendmail.cf using m4 source <p> In the following I will, for simplicity, assume that the sendmail version is 8.8.8. If you have a different version, replace 8.8.8 with that version number below! Also, the instructions will not work for older versions of sendmail. Get the latest sendmail! <p> Download the sendmail source. Try ``http://WWW.Sendmail.ORG'' or possibly ``ftp.sendmail.org''. <p> I also recommend that you obtain my patch for allowing envelope sender reverse aliasing and other nice stuff to really make you take control over your mail environment. Write to ``Sendmail Patch <sendmail@lege.com>'', Subject: ``sendmail-8.8.8'', if 8.8.8 is your sendmail version. They are also available from ``http://www.lege.com'', as is the sgml source of this mini-HOWTO! You don't have to get my patches in order to get ``Queue Remote Mail + Deliver Local Mail'' to work. My patches solve other things. But I just thought this would be a nice place to mention them, as many Linux users will find them extremely useful. (They will even give you properly working virtual domains, if you like. The virtual domains don't have to be ``local''. They will give you ``xaliases'', or in other words ``reverse aliasing''.) Unpack the sendmail source. You may get /usr/src/sendmail-8.8.8/. cd /usr/src/sendmail-8.8.8/cf Now overlay my patch, if you want it, otherwise skip this step: If you don't want to use procmail as Local Delivery Agent, save away your /usr/src/sendmail-8.8.8/cf/ostype/linux.m4 before doing this... Save my patch to ``/tmp/sendmail-8.8.8-cf-cpio-idcmu.gz'', then... <tscreen><verb> cd /usr/src/sendmail-8.8.8/cf gzip -dc < /tmp/sendmail-8.8.8-cf-cpio-idcmu.gz | cpio -idcmu </verb></tscreen> If you didn't want to use procmail, write back the saved copy of /usr/src/sendmail-8.8.8/cf/ostype/linux.m4 again. And regardless of if you applied my patch or not, you must make sure these lines or very similar ones are added to /usr/src/sendmail-8.8.8/cf/cf/yourhostname.smtp.mc (but if you applied my patch you may want to investigate filenames containing the word ``elijah'', under /usr/src/sendmail-8.8.8/cf): <tscreen><verb> dnl # Defer Delivery to &dquot;expensive&dquot; mailers until next time the dnl # queue is processed using &dquot;O HoldExpensive=True&dquot; and make dnl # sure smtp mailers are &dquot;expensive&dquot;. dnl # (See original &dquot;sendmail&dquot; book Chapter 30: Options, dnl # &dquot;Oc - Don't connect to expensive mailers&dquot;, or dnl # 2nd Edition &dquot;sendmail&dquot; book Chapter 34.8.29, dnl # &dquot;HoldExpensive (c), Queue for expensive mailers&dquot;.) dnl # / Leif Erlingsson <leif@lege.com> define(`confCON_EXPENSIVE', `True') define(SMTP_MAILER_FLAGS, e) MAILER(local)dnl MAILER(smtp)dnl </verb></tscreen> <sect1> <!-- 2.3 --> Menu support suggestions <p> The 1.x versions of this document contained Menu support suggestions for /var/X11R6/lib/fvwm/system.fvwmrc. I have dropped those in the current version, but they are available on request: <p> Write to ``Menu support suggestions <fvwmrc@lege.com>'', Subject: ``Menu support suggestions'' <sect> <!-- 3 --> Dial-on-demand solutions PART <p> Written by Jan P Tietze <jptietze@mail.hh.provi.de>. Many Linux users access the Internet through a dialup line, and many have decided to implement dial-on-demand facilities on their system. That is, whenever an IP packet of some sort has to leave the local network or the local host, the link to an Internet Service Provider (ISP) will automatically be established. The link will be dropped after some period of time that no packet has travelled across. Although this is very comfortable and cost effective, there is one special case in which this is neither comfortable (as the time to bring up a &dquot;traditional&dquot; modem dialup is very noticeable) nor cost effective, and this is sending e-mail. E-Mail is commonly sent by SMTP, either delivered by your own system or through a SMTP host on the Internet that usually resides in your ISP's network. With dialup lines, every time you send a message the link will have to be brought up. This is quite okay if you send only one message, but if you happen to create and send multiple messages, bringing up the line more than once can be tedious and cost ineffective. Also, if your ISP imposes limits as to what times you are allowed to login, this would also restrict you to postpone messages at certain times of the day, and you would have to manually send them later. Section 2 of this document will solve the situation, however in situations where an external DNS lookup would cause the link up, the link will still be established even if e-mail is just being queued. The reason is that sendmail wishes to &dquot;canonify&dquot; host names. The solution to this problem is twofold: First, we'll have to moderately change sendmail.cf. And then we have to define the process of actual mail delivery. Personally, I prefer to have cron do the job for me and describe the necessary changes below. <sect1> <!-- 3.1 --> Configuring sendmail.cf <p> For the reasons stated in [2.2], I recommend modifying the m4 sources instead of editing sendmail.cf directly. It will actually save you a lot of hassle and make configuration changes more verbose. First, perform all the changes described in the first part of this document. Then go through the dial-on-demand specific stuff. <sect2> <!-- 3.1.1 --> Configuring sendmail.cf directly, for trivial configurations <p> Configuring directly is highly impractical and anything but verbose, but obviously, this is your decision. Close to very bottom of your sendmail.cf should be a line that reads: <tscreen><verb> R$* < @ $* $˜P > $* $: $1 < @ $[ $2 $3 $] > $4 </verb></tscreen> Precede that line with a &dquot;#&dquot; so that it reads <tscreen><verb> #R$* < @ $* $˜P > $* $: $1 < @ $[ $2 $3 $] > $4 </verb></tscreen> <sect2> <!-- 3.1.2 --> Configuring sendmail.cf using the m4 source. <p> Add the following line to /usr/src/sendmail-8.8.8/cf/cf/yourhostname.smtp.mc: <tscreen><verb> FEATURE(nocanonify)dnl </verb></tscreen> Your final sendmail.cf can then be built by issuing the following commands. Remember to always back up your old /etc/sendmail.cf before installing the new one: <tscreen><verb> cp /etc/sendmail.cf /etc/sendmail.cf.bak cd /usr/src/sendmail-8.8.8/cf/cf m4 yourhostname.smtp.mc > /etc/sendmail.cf </verb></tscreen> <sect1> <!-- 3.2 --> Adding dial delay <p> It is oftentimes useful, especially when using modem lines, to have a dial delay installed. This means that if sendmail tries to initiate a connection in an attempt to send an e-mail (and this causes the line to go up) but the link actually takes more time to get established than what sendmail thinks should be a reasonable timeout, sendmail will simply wait some seconds and then retry. <sect2> <!-- 3.2.1 --> Configuring sendmail.cf directly <p> Somewhere in your sendmail.cf could be a line that would read: <tscreen><verb> #O DialDelay=10s </verb></tscreen> (or very similar). Delete the ``#''. If there's no ``#'' at the beginning of the line, things should be considered okay (it just means this had already been enabled before). If there is no such line in your sendmail.cf, add one (it is a wise thing to do to add this in the &dquot;options&dquot; part of the file): <tscreen><verb> O DialDelay=10s </verb></tscreen> Now change the ``10s'' part to the number of seconds you deem suitable. <sect2> <!-- 3.2.2 --> Configuring sendmail.cf using m4 source <p> Add the following line to /usr/src/sendmail-8.8.8/cf/cf/yourhostname.smtp.mc: <tscreen><verb> define(`confDIAL_DELAY',`10s') </verb></tscreen> Now change the ``10s'' part to the number of seconds you deem suitable. Your final sendmail.cf can then be built by issuing the following commands. Remember to always back up your old /etc/sendmail.cf before installing the new one: <tscreen><verb> cp /etc/sendmail.cf /etc/sendmail.cf.bak cd /usr/src/sendmail-8.8.8/cf/cf m4 yourhostname.smtp.mc > /etc/sendmail.cf </verb></tscreen> <sect> <!-- 3 --> Delivering e-mail <p> E-Mail delivery can be invoked by issuing the command &dquot;sendmail -q&dquot;. For those who are interested in what sendmail actually does, &dquot;sendmail -q -v&dquot; will give a more verbose version of the delivery process. It is very convenient to automate the process of e-mail delivery. A tool commonly used for this process is cron. <sect1> <!-- 3.1 --> How to have e-mail delivered at special times. <p> Edit your crontab: <tscreen><verb> crontab -e </verb></tscreen> Add lines of the form: <tscreen><verb> 05 18-23,0-7 * * Mon,Tue,Wed,Thu,Fri /usr/sbin/sendmail -q 05 * * * Sat,Sun /usr/sbin/sendmail -q </verb></tscreen> Please refer to the crontab man page (available through &dquot;man 5 \ crontab&dquot;) for further information. I think the format is pretty obvious. The example crontab entries shown above send e-mail (if, and only if, e-mail is available from the queue) 5 minutes after an hour on weekdays, starting at 6:05 pm, and stopping at 7:05 am. On weekends, e-mail is delivered 5 minutes after an hour, starting at 12:05 pm on Saturday, and stopping 11:05 pm on Sunday. As a dial-on-demand user, it is sometimes desirable to have your system collect your e-mail via the POP3 protocol at certain times of the day. You could therefore add an entry similar to the following to your crontab: <tscreen><verb> 0 21 * * * popclient -3 -u <your pop3 user name goes here> -p <put your password here> -o /var/spool/mail/<the user on your system that should receive the collected e-mail> <mailhost.somedomain.com> </verb></tscreen> Of course, this should all go on a single line. Then, save the file and leave the editor. The crontab should now be installed. <sect> <!-- 5 --> Automatic Masquerading (Address Translation) <p> Written by Vincent Zweije <zweije@xs4all.nl>. <p> This method uses the <em/generics database/. This is not a trivial solution in the sense that you can quickly edit your <tt/sendmail.cf/ by hand. Write up a <tt/sendmail.mc/ and use the m4 macro language method instead. Really. <p> Words marked with an asterisk[*] can be looked up in the glossary at the end. <sect1> <!-- 5.1 --> The Situation... <p> Suppose you have a dialup account at an ISP. On your own machine, you have your working account, the name of which is different from the one at your ISP. Consequently, your local and global email addresses differ. <p> When mail gets sent out, it would be a nice feature to automatically masquerade[*] your local email address to the global one as known at your ISP. Sendmail can do this by means of the <em/generics table/. You can also have multiple local email addresses, and masquerade them all to your email addres at your ISP. You can even have accounts for friends on your machine, and translate their addresses on your machine to their email address at <em/their/ ISP. Ergo: the generics table is useful. <p> You never have to worry again about setting a <tt/Reply-To/ or a <tt/From/ in your email. And you are sure that bounces[*] arrive back in your ISP's mailbox instead of being lost because of a bad return address[*]. <sect1> <!-- 5.2 --> Setting Up the Generics Table <p> The generics table is a table that maps locally valid email addresses to globally valid email addresses. The correct term for this is &dquot;masquerading&dquot;. Masquerading translates email addresses, but it does <em/not/ change where a message gets sent by your sendmail. (If you want to reroute messages, you need aliasing.) <p> A good place for the generics table is <tt>/etc/mail/generics</tt>, but you can configure any place you like in your <tt/sendmail.mc/. The generics table has one line for each masquerade. The line contains two addresses separated by white space; the first address is masqueraded into the second. Here is a little example. <tscreen><verb> $cat /etc/mail/generics lerlings leif@lege.com jtietze tptietze@mail.hh.provi.de vzweije zweije@xs4all.nl $ </verb></tscreen> <p> After you have changed the generics table, you must rebuild the index to it. You need the <tt/makemap/ program, which comes with the sendmail distribution. Go to <tt>/etc/mail</tt>, and run <tscreen><verb> #makemap -hash generics <generics # </verb></tscreen> The index is now built. <p> For instance, the username I use on my home machine is "vzweije". So, on my home machine my email address is <vzweije> (there is no domain involved). When mail gets sent out, the occurrences of <vzweije> in the header[*] and the envelope[*] are masqueraded into <zweije@xs4all.nl>, which is the address of my mailbox at my ISP. <sect1> <!-- 5.3 --> Making Sendmail Use the Generics Table <p> The following lines in sendmail.mc configure sendmail to actually use the generics table. <tscreen><verb> $cat /etc/mail/sendmail.mc [...] FEATURE(genericstable, hash /etc/mail/generics) GENERICS_DOMAIN(love.sense.net sense.net love) FEATURE(masquerade_envelope) FEATURE(allmasquerade) [...] $ </verb></tscreen> Feature "genericstable" tells sendmail to use the generics table. The extra argument, hash /etc/mail/generics, tells sendmail where the generics table is, and what type of index (hash) there is to it. <p> "Generics_domain" defines the domains to which you wish to apply the generics table. Normally you don't need this, because the generics table applies to local addresses by default. However, you may have a local network to which you have assigned a mail domain, which you wish to masquerade too. <p> Feature "masquerade_envelope" applies the rewriting process to the mail envelope[*] as well as to the mail header[*]. It means that bounces[*] of outgoing mail will be sent back to your ISP mailbox. If you did not have this, the bounces would be undeliverable because your local address is unknown outside your own machine. <p> Feature "allmasquerade" applies the rewriting process to recipient addresses as well as to sender adresses. It is useful if you send yourself a local Cc of an outgoing mail; the other recipient will see a Cc to an address he knows instead of a local address. You want this. <sect> <!-- 6 --> Glossary <p> <descrip> <tag/Alias/ An alias is a way of forwarding an e-mail address to one or more new destinations. <tag/Asterisk/ Star-like symbol, ASCII code 42 decimal. Usually rendered six-pointed, but has also been spotted with five or eight points. <tag/Bounce/ Returned, undeliverable mail. Also the act of returning undeliverable mail. Bounces are returned to the sender address in the envelope[*] of the mail; the sender given in the header[*] is <em/not/ used. <tag/DNS/ Dynamic|Distributed Name Server|System. A mechanism on internet to find addresses and other things associated with host names. <tag/Envelope/ Information about a mail message that is not in the header. This information is used by MTAs[*] to determine where mail must go, and if not deliverable, where it is to be returned. This information is typically transferred with commands of the SMTP[*] protocol. <tag/ESMTP/ Extended SMTP[*]. Has some more features. <tag/Header/ The initial part of a mail message, containing more or less meta information about the message; who sent it, what it is about, what it looks like, to whom you are to answer, etc. The structure and meaning is described in RFC[*] 822. <tag/Mailbox/ A destination where mails are sent to. It is more general than your in-box that contains the mails delivered to you. A mailbox can also be a program (which prints the mail to a printer) or other things. <tag/Mail domain/ The part after the @ of an email address. This is often called the "fully qualified host name", but with more modern mail transport (MX records), it's not really a host any more. So I prefer the term "domain". <tag/Mailer/ A "channel" for sendmail via which to output mails. This is a very general concept, including talking SMTP[*] or UUCP[*] to other mail servers, delivering a mail to a mailbox, piping a mail to a program; anything via which a mail can be sent ending up of sendmail's control. <tag/Masquerade/ Translate an address. This is the pure act of translation; it does not necessarily mean that the mail gets sent to another place. For redirecting e-mails there is aliasing[*]. <tag/MTA/ Mail Transfer Agent. A program that transfers mail from one place to another. Sendmail is an MTA. <tag/MUA/ Mail User Agent. A program that manages mail messages (on behalf of a user). Eudora, elm, pine, etc. are examples of MUAs. <tag/Return Address/ Place where to send the bounce[*] when an email turns out undeliverable. The return address is in the envelope[*] of the email. Some people know this as the "From " header[*], since it often saved in mailboxes looking like a header line. It really isn't; it's part of the envelope. <tag/RFC/ Request For Comments. Documents written as proposal for a standard on the internet. They do not always make it to standard, but the ones about SMTP[*] (RFC 821) and mail message structure (RFC 822) did. <tag/SMTP/ Simple Mail Transfer Protocol. A commonly used protocol (language) used by MTAs[*] to exchange mail. Described in RFC[*] 821. <tag/UUCP/ Unix to Unix CoPy. A protocol used on many unix systems to transfer files between them. E-mail can also be transferred with this system. </descrip> </article>