Sendmail and Fetchmail: A local mail server


System Administration


[Photo de l'auteur]


Original in fr John Perr

fr to en:John Perr


Linux user since 1994; he is one of the French editors of LinuxFocus.


This article explains how to configure sendmail and fetchmail on your local computer connected to the internet via a PPP link. Such a configuration allows you to use every Unix mail client (not only Netscape). You can send and fetch your messages each time you establish a PPP connection.





In order to manage properly mail on your linux box, you have to configure a Mail Transfer Agent (MTA in short). The most popular (and older) is certainly sendmail but there are others such as qmail which are faster and simpler to configure, or exim which is included in standard Debian configurations. We shall stick to sendmail here and use a configuration kit from Berkley University by Eric Allman.
To retreive your mail stored on the server of your Internet Service Provider (ISP in short), it will also be necessary to configure fetchmail in order to feed sendmail with the content of your mailboxes. fetchmail is for mail retrieval via pop3 or imap. You can also use uucp but that is a more exotic case not covered by this article.


It is necessary to install the following packages to configure sendmail (rpm format):

Dependent on your distribution you may have slightly different names. The version numbers could also be different. Only the first two packages are really needed.

To actually configure sendmail, follow these steps:

  1. first we assume that:
  2. first create a file: /usr/lib/sendmail-cf/cf/ which contains:
    # start of
    define(`SMTP_MAILER_FLAGS', `e9')dnl
    GENERICS_DOMAIN(localhost.localdomain localhost localhost)
    define(`confCF_VERSION',`dede's cf - 22/05/98')dnl
    # End of

    The line define(`SMART_HOST'.... tells sendmail to send all outgoing external mail via your provider instead of trying to deliver it directly. Your internet service provider will then take care of further distribution.
  3. Also create /etc/genericstable:
  4. Verify that /etc/alias contains at least:
    MAILER-DAEMON:  postmaster
    postmaster:     root
  5. Modify or create /etc/nsswitch.conf as follow:
    passwd:     files  
    shadow:     files  
    group:      files  
    hosts:      files   dns
    services:   files
    networks:   files
    protocols:  files
    rpc:        files
    ethers:     files
    netmasks:   files     
    bootparams: files
    automount:  files 
    aliases:    files 
    (Each entry should contain "files" alone except host)

  6. Generate /etc/ with:
    m4 > /etc/
    and permissions as such:
    -rw------- 1 root root 26468 mai 12 22:52 /etc/

  7. Generate the address conversion data base:
    /usr/bin/sendmail -bi -oA/etc/genericstable
    A file /etc/genericstable.db should have been created

  8. Re-read the alias table:

  9. The file /etc/hosts should contain a line similar to: localhost.localdomain localhost localhost

  10. restart sendmail:
    kill `head -1 /var/run/`
    /usr/bin/sendmail -bd -os

    Test sendmail

    That's all for sendmail.We now have to check that everything works nicely:
    Make a file named test.mail with the following lines:

    Subject: test local
    first line of my message
    (compulsory blank line)

    and do:
    /usr/bin/sendmail -v dede < test.mail

    The following lines should display:

    dede... Connecting to local
    dede... Sent

    Run mail or any other mail client (not yet netscape !!) and check that the message has been received

    In order to configure Netscape to read local mail (served by sendmail):

    You can also use chmod 777 but this change can be a security hole if you are not the only one connected to your box. chmod 1777 means only the owner of the file can delete it and not the persons with write permission to the directory.

    From now on, your own PC is serving mail directly to Netscape even if you are not connected to the Internet. You can of course use other mail clients like XFmail, emacs, mutt, pine etc...

    Configuration of fetchmail

    Before we try our new mail server on the Internet, we need to configure fetchmail in order to tranfert messages stored in your mailboxes of your ISP:
    create a file .fetchmailrc in /home/dede:

    poll protocol POP3
            user toto is dede 
            password XXXXXXX

    where toto and XXXXX are the login and password of your mail account at If you have more than one mailbox, just duplicate the above lines for each mailbox you have.
    The file .fetchmailrc must have permissions set as follow, otherwise fetchmail will refuse to run:

    -rw-------   1 dede   dede   189 oct  6 21:45 /home/dede/.fetchmailrc

    Now, for a test on the Internet:

    It should appear in the mail queue when issuing the command: mailq Next, connect to your ISP ( and send the message:
    /usr/bin/sendmail -q

    sendmail -q flushes the mail queue of sendmail and causes it to send out the mail now. Wait for a while and type fetchmail to get your mail, you should have a message sent back by the mirror. You can now disconnect if all the messages have arrived.


    Once all is setup, we still have to make it work on its own each time a connection is established.

    With PPP, files /etc/ppp/ip-up and ip-down are executed each time you connect or disconnect. Check that you have a line like this one in these files, otherwise create it:
    [ -x /etc/ppp/ip-down.local ] && /etc/ppp/ip-down.local $*
    In /etc/ppp/ip-up you add:
    [ -x /etc/ppp/ip-up.local ] && /etc/ppp/ip-up.local $*

    Files /etc/ppp/ip-up and ip-down then lauch files ip-up.local and ip-down.local that we wrtite like this:

    # /etc/ppp/ip-up.local
    #Record connection parameters
    echo `date` $4 $5 ppp-on >> /etc/ppp/history
    tail -n 1 connect-errors >> /etc/ppp/history
    # Send waiting mail
    echo Sending mail... > /dev/console
    /usr/sbin/sendmail -q
    echo Mail sent.  > /dev/console
    # Get mail waiting on the pop server
    echo Getting mail... > /dev/console
    fetchmail  > /dev/console 2>&1
    echo Got mail.  > /dev/console
    exit 0
    # end of /etc/ppp/ip-up.local

    In fact, the two important lines are commands sendmail -q and fetchmail. The others are cosmetic and allow:

    # /etc/ppp/ip-down.local
    #Record connection parameters
    echo `date` ppp-off >> /etc/ppp/history
    exit 0
    # end of /etc/ppp/ip-down.local

    These files are run as root, so it is necessary to copy the file .fetchmailrc in the /root folder.

    If you have a permanent access to the Internet, sendmail regularly sends mail if it has been started as a daemon with the following command:
    sendmail -bd -q10m
    In order to send your mail every 10 minutes for exemple.
    fetchmail can also be lauched in daemon mode with the command:
    fetchmail -d 600
    In order to retreive your incoming mail every 10 minutes (600 seconds) for instance.

    Usually this type of commands are located in the startup (or init) files in the directory /etc/rc or /etc/rc.d/ (may vary according to your configuration).


    With such a configuration, the outgoing mail waiting in the queue (mailq) is sent. The incoming mail waiting in your mailbox on the server of your ISP arrives. You can use xbiff or xmailbox or any other similar software to warn you that you have mail. You can also fine tune the way your mail is sorted and filtered with procmail. This last step is explained in the Novembre 1997 article from Angel Lopez.

    Other related articles

    Documentaion on sendmail and fetchmail: