Linux
An Off-Line Email System


Even if you can read emails online, it is a very good way to waste your money. What can you do to save money?

There are two programs which allow an off-line work at home. The first is sendmail, the second is popclient.

But before we explore sendmail and popclient we have to edit the file /etc/hosts and to insert one entry for the mail server. If you have created i4l.config and called "makeleaf" this is done already. If you did not do it, you must add:

/etc/hosts (cutting)
  <IP address>  <name_of_mail_server>    getmail

sendmail

I will not explain the low level configuration of sendmail - this is somewhat for masochists ;-) I'm using a Linux distribution (S.u.S.E. aktuell 4.2 June 96; ELF) with a sendmail version R8. It is configurable with some m4 scripts - have a look at the README of sendmail. I prepared a slightly modified configuration of the suggested original ("linux.smtp.mc"). Go to /usr/src/sendmail/cf/cf and write a file linux.asyoulike.mc, e.g.:
/usr/src/sendmail/cf/cf/linux.asyoulike.mc  # Bernhard's sendmail.cf
  include(`../m4/cf.m4')dnl              # must be!!!
  VERSIONID(`asyoulike')dnl       # name it as you like
  OSTYPE(linux)dnl                       # We're doing Linux!
  FEATURE(nodns)dnl                      # No own name server
  FEATURE(nocanonify)dnl                 # Don't lookup DNS while sending
  FEATURE(nouucp)dnl                     # We don't use UUCP
  define(SMART_HOST, relay:<provider.name>)dnl   # mail to ...
  define(confCON_EXPENSIVE, True)dnl     # distributing mail is expensive
  MASQUERADE_AS(lrz.uni-muenchen.de)dnl  # we act as "provider"
  define(confUSERDB_SPEC, /etc/userdb.db)dnl  # Address correction
  FEATURE(notsticky)dnl                  # don't change From: line
  MAILER(local)dnl                       # use mailer:
  MAILER(smtp)dnl                        # local, Simple Mail Transfer Prot.
You just must tell sendmail this now:
  root:# m4 linux.asyoulike.mc > /etc/sendmail.cf
  root:# _
Writing emails you have to tell your address so that a "reply" works properly. This means, the From: line in the email header must contain your account name at your provider. This happens because of the line "MASQUERADE_AS ..." in the m4 script, and because of a user database built in there. This database (/etc/userdb.db) also must be prepared, therefore you must create a file containing two lines per user:
/etc/userdb.db
  <login_at_your_pc>:mailname  <provider_login_name>
  <provider_login_name>:maildrop <login_at_your_pc>
It must be changed to a format sendmail can read:
  root:# makemap btree /etc/userdb.db < /etc/userdb
  root:# _
(sendmail-FAQ tells that this only works, if you have the Berkeley db package - the S.u.S.E. 4.2 installs it.)

Now you have after a reboot (or after killing sendmail and restarting it with the option "-bd") a working mail slave.

Sendmail is running as daemon in the background. You can tell him to collect all the email you wrote (it will be stored in /var/spool/mqueue or /var/mqueue), and to send it on demand only.

Therefore you must start sendmail while booting as daemon without the "-q ..." option. In simpleinit environment this happens in the last part of the startup script /etc/rc.d/rc.M; if you have sysvinit it is in an extra file (SuSE 4.2: /sbin/init.d/sendmail. Here you must remove this option; "-bd" must remain, because it is the command for sendmail to go into background as daemon.

Mailer's Will...

Sending mails with the classical UNIX command mail works correctly now. The header is written properly, and the From: line contains the correct email address at your provider.

But there are some mail programs which are something obstinate. Programs like pine or Netscape overwrite the header with some entries, which are not correct.

Mutt

Jan Berkel <jan.berkel@on-line.de> wrote me this hint: You need to edit .muttrc in your home directory and to add the following line:

my_hdr From: foo@foonet.com (Foo Name)
With this the header rewriting works.

Netscape

For Netscape you can edit the file ~/.netscape/preferences. In it you find the line

~/.netscape/preferences (cutting)
  [...]
  EMAIL_ADDRESS:          <Email@Address>
  [...]
Type in your correct email address.

Pine

Tilo Winkler <twinkler@uni-paderborn.de> found out how to manage it that pine does not write garbage into the From: line. You must get the pine source code and edit pine/makefile.lnx: add -DALLOW_CHANGING_FROM at the CFLAGS and recompile. Now you can add the following to .pinerc in your home directory:

customized-hdrs=From: My Name <My@email.address>,
                Reply-To: My Name <My@email.address>
XEmacs

(Thanks, Markus Dickebohm <m.dickebohm@uni-koeln.de> for sending me these hints!)

You can fake the From: address within XEmacs, if you edit the file ~/.emacs and add the following entries:

        (setq user-mail-address "m.dickebohm@uni-koeln.de")
        (setq mail-host-address "mail.rrz.uni-koeln.de")
This is not ideal, like the mailer programs above: this mailer changes the mailer header.

More Mailers

If you have information about other MUAs (Mail User Agents), please send them to me. Thank you!

popclient

Popclient is a simple-to-use program. Use it this way:
  ~:#    popclient -3 -u<host-login> -p<host-password> -o/var/spool/mail/<user> getmail
  ~:# _
getmail is the mailhost defined in /etc/hosts. If you give an additional "-k" as option, the emails at the provider will not be erased.

Hint: In the meantime a powerful child of popclient was born: fetchmail. Sorry, but I'm not familiar with fetchmail until now.

A Script

This script manages the fetching and sending of your emails. If you are lucky this takes so few time, that only one telephone tariff unit is lost. Some cosmetics in it create a readable log output of the running transfer. You create this script as root and store it in /sbin. This file is also written now in a way which allows more open applications at one time - it uses the file /sbin/isdn which we discussed in the last chapter.
/sbin/transmail
  #!/bin/sh
  # transmail.sh: exchanges email with the provider.
  # Author:       Bernhard Hailer <dl4mhk@lrz.uni-muenchen.de>
  # Version:      4.0 (27-Jan-97)

  PATH=/sbin:/usr/sbin:/bin:/usr/bin

  . /etc/i4l.provider
  . /etc/i4l.secrets

  cd /                                # against PATH=. effect 

  echo -----------------------------------------------------------------------
  echo -e "Starting mail transfer: \c"; date

  . /sbin/connect on

  echo "Checking mail server..."
  set `ping -qc5 -i1 getmail | grep transmitted`
  if [ $4 -gt 0 ]      
  then
    echo ":-) Mail server online - starting mail exchange"  
    echo "Sending mail..."
    sendmail -q
    echo "Again sleeping 1 sec for PPP handshaking"
    sleep 1
    echo "Fetching mail..."
    popclient -3 -u $MAIL_LOGIN -p $MAIL_PASSWD -o $MAIL_PATH getmail
    echo "Again sleeping 1 sec for PPP handshaking"
    sleep 1
  else
    echo ":-[ Sorry - mail server is down. Try later..." 
  fi  

  . /sbin/isdn off

  # allow dl4mhk access to mail:
  chown dl4mhk.users /var/spool/mail/dl4mhk

  echo -e "Finished mail transfer: \c"; date
The sleep commands are important: the connection may hang without them.

Let's cron!

If you want to run your computer twentyfour hours a day, you could create an automatic mail transfer using the cron daemon. Therefore do:

1.) modify cron table.

  root:# cd ~
  root:# cp /var/spool/cron/crontabs/root .crontab
  root:# _
Append the following lines to the file .crontab:
  # Transfer mail
  30 04 * * * /sbin/transmail.sh 1>> /var/log/transmail-log 2>> /var/log/transmail-log
2.) Tell crond these modifications.
  crontab .crontab
Now the clock in the computer automatically handles all the emails. Each night at 4:30 a.m. the mails are fetched and sent. Remark: Of course the system time must be set properly - man date; man clock.

You need to calculate what's more expensive: telephone or electricity. Electricity is expensive. But I use this system because it is so comfortable...


Copyright © (GPL V 2) 1996 Bernhard Hailer
Last modification: 21-Feb-97