Sendmail and dial-up modem internet

This document is (C)opyright 1999 by Wouter Hanegraaff. He doesn't maintain it anymore, but gave us the permission to reproduce it here.
A translation into russian is available from Marek 'Marx' Grac.

Introduction

This document describes how to configure sendmail for users who do not have a direct internet connection, but use a dial-up account with an ISP to connect to the internet.

Motivations

I wanted to be able to send and receive e-mail from my linux box at home that didn't have a permanent connection to the internet.
Problems with sendmail and dial-up accounts include
  • Mail errors caused by sendmail trying to send messages when no internet connection is available. Sendmail should only try to send outgoing mail if a dial-up connection is active. Also, sendmail shouldn't complain if it can't send messages for a few hours.
  • Sending mail can take a long time if the domain you are sending mail to is far away, or has a bad connection. To resolve this problem, ISP's often offers a SMTP server. By default, a smart-host is not used by sendmail.
  • Being unable to send mail because messages are refused because the local host/domain does not exist. This is typicaly the case when a direct internet connection is not available.
  • If the above is not the case, messages will appear to be sent from a machine that doesn't exist on the internet, or from an e-mail address that is incorrect. This is the case when the local username differs from the account name in the e-mail address. E.g. my username at my local machine is wouter, but my e-mail starts with hanegraa which is my account at my university's mail system. In this case masquerade_as isp.domain.dom won't help, and will result in messages appearing to be sent by localuser@dialup.domain, which is definitely wrong.
  • Instructions

    The solution to these problems involves configuring sendmail and creating some additional files which sendmail will use to convert the headers. The following will work for sendmail 8.8.7 or higher ( I am using sendmail 8.8.7, higher versions should work also, older versions _may_ work). We must create a config macro file from which we can create the sendmail.cf file. Change the /usr/lib/sendmail-cf/cf/yourhost.m4 file (The exact location of the cf directory may differ from your configuration) to something like the following:
    divert(0)
    VERSIONID(`@(#)sendmail.mc  8.8.7 ')
    OSTYPE(yourOs)dnl
    
    FEATURE(masquerade_envelope)dnl
    FEATURE(genericstable)
    GENERICS_DOMAIN(myhost) 
    GENERICS_DOMAIN(myhost.mysubdomain.mydomain.dom)   
    GENERICS_DOMAIN(mysubdomain.mydomain.dom) 
    
    dnl # Defer Delivery to "expensive" mailers until next time the
    dnl # queue is processed using "O HoldExpensive=True" and make
    dnl # sure smtp mailers are "expensive".
    dnl # (See original "sendmail" book Chapter 30: Options,
    dnl # "Oc - Don't connect to expensive mailers", or
    dnl # 2nd Edition "sendmail" book Chapter 34.8.29,
    dnl # "HoldExpensive (c), Queue for expensive mailers".)
    dnl #                           / Leif Erlingsson 
    define(`confCON_EXPENSIVE', `True')
    define(SMTP_MAILER_FLAGS, e)
    define(`confTO_QUEUEWARN', `16h')
    define(`SMART_HOST', `mysmtp')
    
    MAILER(local)dnl
    MAILER(smtp)dnl
    
    
    The masquerade_envelope feature tells sendmail to rewrite not only the headers but also the envelopes. Mailservers on the internet will look at the envelope, and if it contains erroneous addresses, it will bounce the message.
    The genericstable feature causes sendmail to rewrite the from address as defined in the /etc/mail/genericstable file. The GENERICS_DOMAIN lines define for which hosts/domains sendmail should rewrite the message headers and envelopes using the genericstable.
    The define(`confTO_QUEUEWARN', `16h') line will tell sendmail not to complain if it isn't able to send a mail for less than 16 hours. This is useful if you have your computer automaticly check and receive e-mail once or twice a day. Normally sendmail starts complaining after 4 hours, which is too soon for me.
    The smarthost line configures sendmail to use the smtp server of our internet provider. This is not necessairy, but it can speed up sending mail because sendmail will now transfer mail to yous isp's smtp which is usually fast.
    The mailer parts make sure mail is only sent when an internet connection is active. Otherwise, it stays in the mailqueue.
    Now, we are ready to create a sendmail.cf file from the yourhost.m4 file. Cd to sendmai_cf_dir/cf and execute the follolwing command:
    m4 ../m4/cf.m4 yourhost.m4 > yourhost.cf
    
    Make a backup of your /etc/sendmail.cf and copy yourhost.cf to /etc/sendmail.cf.
    The last but most important part comes now: create a file /etc/mail/genericstable . My genericstable file looks like this:
    wouter@duckman.sloterdijk.nl  hanegraa@wins.uva.nl
    wouter@duckman  hanegraa@wins.uva.nl
    wouter  hanegraa@wins.uva.nl
    
    Maybe the first line suffices, but the last lines won't hurt.
    makemap hash /etc/mail/genericstable < /etc/mail/genericstable
    
    After restarting sendmail, things should work now.

    Testing the configuration

    We can test if addresses are rewritten correctly by running sendmail in test mode:
    14 wouter@duckman ~/docs 15:14 > sendmail -bt
    ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
    Enter  <address>
    > 3,1,10,4 wouter@duckman.sloterdijk.nl
    rewrite: ruleset   3   input: wouter @ duckman . sloterdijk . nl
    rewrite: ruleset  96   input: wouter < @ duckman . sloterdijk . nl >
    rewrite: ruleset  96 returns: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset   3 returns: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset   1   input: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset   1 returns: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset  10   input: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset  50   input: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset  50 returns: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset  94   input: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset  93   input: wouter < @ duckman . sloterdijk . nl . >
    rewrite: ruleset   3   input: hanegraa @ wins . uva . nl
    rewrite: ruleset  96   input: hanegraa < @ wins . uva . nl >
    wins.uva.nl: Name server timeout
    rewrite: ruleset  96 returns: hanegraa < @ wins . uva . nl >
    rewrite: ruleset   3 returns: hanegraa < @ wins . uva . nl >
    rewrite: ruleset  93 returns: hanegraa < @ wins . uva . nl >
    rewrite: ruleset  94 returns: hanegraa < @ wins . uva . nl >
    rewrite: ruleset  10 returns: hanegraa < @ wins . uva . nl >
    == Ruleset 10,4 (10) status 75
    rewrite: ruleset   4   input: hanegraa < @ wins . uva . nl >
    rewrite: ruleset   4 returns: hanegraa @ wins . uva . nl
    >                                                             
    
    If this works, we're all set! Outgoing mail will be queued but not delivered (there's usually no internet connection so this is a good thing). So, after connecting to the internet we have to make sure mail is sent using the command sendmail -q
    copyright 1999: Wouter Hanegraaff