Previous Next Table of Contents

14. Sendmail

14.1 /etc/sendmail.cf - the monster

/etc/sendmail.cf is the configuration file that talls sendmail how to work. It is (arguably) not human readable. However there are m4 macros that make it easy to configure. You generate /etc/sendmail.cf from /etc/sendmail.mc

14.2 /etc/sendmail.mc - edit this

        divert(-1)
        include(`../m4/cf.m4')
        VERSIONID(`/etc/sendmail.mc - gets most people going')
        Cwlocalhost trix.trix.priv trix.dircon.co.uk
        define(`SMART_HOST', mailhost.dircon.co.uk )
        OSTYPE(linux)
        FEATURE(nouucp)
        MAILER(local)
        MAILER(smtp)
        FEATURE(nodns)

Note the relative path in include(`../m4/cf.m4'), that hints which directory you should be in when running m4.

Don't forget to substitute your names, in place of trix (etc). All outgoing email will be routed via your SMART_HOST (preferably not mine, unless you want me kicked off).

14.3 Installing /etc/sendmail.mc --> /etc/sendmail.cf

        cd /usr/src/sendmail/cf         # so that m4 finds the other files
        m4 < /etc/sendmail.mc > /etc/sendmail.cf
This generates /etc/sendmail.cf from the above /etc/sendmail.mc file. After that the .mc file isn't used, but /etc/is a sensible place for it.

If that worked, read-on, restart sendmail and test it (job done). You must restart sendmail for every change to the .cf file.

14.4 What is Sendmail?

Sendmail is all about receiving and transmitting email between machines. It delivers your mail into /usr/spool/mail/$LOGNAME, where you can read it.

You compose an EMAIL using pine or elm. It calls sendmail to send it. Sendmail accepts the message and either delevers it immediately or adds it to the queue to be processed.

To send a message, sendmail (usually) looks up the name of the destination host using the nameserver. The nameserver (after asking another nameserver) replies with the MX record for that host.

The MX record, (mail-exchange), is a 'top-two' list of IP addresses, of the destination host and it's backup mail exchanger. Sendmail than tries the hosts in that order, to find the most direct path, or the nearest intermediary.

With the above .mc file, sendmail sends it to the smart-host ie your ISP's mailhost, and lets it do most of the work.

Sendmail calls that host in TCP/IP port 25, and expects it to talk SMTP.

14.5 Sample SMTP session - how it works

This is what happens behind the scenes, normally you use PINE or ELM to call sendmail to do this. To do this to localhost, you need sendmail installed to accept the call, but if you contact a remote host, you only need telnet.

If you ever get stuck and cannot SEND mail, you can do this manually. Use cut and paste to save some editing mistakes.

        # blank lines added for clarity
        # and markers in the margin

        gps@trix:~$ telnet localhost smtp

        Trying 127.0.0.1...
        Connected to localhost.
        Escape character is '^]'.
        220-trix.dircon.co.uk Sendmail 8.6.12/8.6.12 ready at Mon, 4 Mar 1996 00:18:21 GMT
        220 ESMTP spoken here

 -->    HELO
        250 trix.dircon.co.uk Hello gps@localhost [127.0.0.1], pleased to meet you

 -->    VRFY gps
        250 Graham Swallow <gps@trix.dircon.co.uk>

 -->    MAIL FROM:<gps@trix.dicon.co.uk>
        250 <gps@trix.dicon.co.uk>... Sender ok

 -->    RCPT TO:gps
        250 gps... Recipient ok

 -->    DATA
        354 Enter mail, end with "." on a line by itself

 -->    To: john
   |    From: Graham
   |    Subject: Junk Mail
   |    X-extra: Extra lines in the header for those who want them
   |    don't you just love it?
   |    G
 -->    .
        250 CAA00694 Message accepted for delivery

 -->    QUIT
        221 trix.dircon.co.uk closing connection
        Connection closed by foreign host.

        gps@trix:~$ 

Notice the strange To: and From: lines in the text part of the message! This is part of how spoofing works.

When your ISP or another internet user (directly) sends you an email, they connect to TCP/IP port 25 on your host, and expect it to talk SMTP. Sendmail is also the program that implements SMTP, and handles incomong email.

Sendmail also does various tricks like aliases, lists of users and delivering email to your scripts, for automatic processing. It also talks to machines that use different systems (uucp transports or different message formats).

14.6 Sendmail - requires ...

Get dial_up Internet working (done). Select Sendmail (not Smail) from the N disks (Slackware). Ensure that your /etc/HOSTNAME is the proper email name, and that /etc/hosts is correct, with the full hostname first on the line after the actual address. Create your user. Check that your names get resolved (/etc/resolv.conf), so that ping www.InfoMagic.com works. (Without the address in /etc/hosts, it must have come from the nameserver).

14.7 Slackware - /etc/sendmail.cf

It is better to generate your own sendmail.cf file, but slackware comes with two prepared .cf files, that simply drop-in. However, they might not be right for you. When you install sendmail from the N disks, the following script gets run. NOTE: this will overwrite your own /etc/sendmail.cf file, but that's easily replaced.

        cd /var/adm/setup
        ./setup.sendmail
Select option 1, ie the one that uses a nameserver. This tell sendmail to use MX (mail exchange) records, ie dns.

When I did this, I had problems when not connected to the Internet. Basically, sendmail requested the MX record for that host, but got nothing (no route to nameserver). Sendmail then immediately rejected my email (instead of putting it in a queue for later).

Even worse, sendmail wants to use DNS to confirm its own address. Local traffic won't get sent until the modem comes back online!

I fixed this for me, by selecting nodns (in my own sendmail.mc) and by specifying a default route. Now all my email goes out via felix (mailhost.dircon.co.uk), but incoming mail can be accepted direct.

14.8 testing a new /etc/sendmail.cf

Restart sendmail and send a few messages. Start Internet (dip_in or dial_ppp tdc) and test that you can send and receive to/from your ISP.

        tail -f /var/adm/messages &;    # start this once

        killall sendmail        # ensure not using old .cf file!
        ps -xa                  # none running
        sendmail -bd -q 15m     # process queue every 15 minutes 
        telnet localhost smtp   # what your machine looks like HELO QUIT

        echo help | sendmail user3      # yourself
        mailq                           # view list in queue
        sendmail -q                     # process queue now
        pine                            # read mail in other window

        echo help | sendmail user                       # yourself
        echo help | sendmail user@hostname.domain       # yourself

        dial_ppp tdc                    # connect to Internet -or-
        dip_in                          # connect to Internet
        ping isp-mailhost.domain        # your ISP's mailhost

        # the long address is a special format that ROUTES
        # that email to yourself via your service provider
        # the 'quotes' make < and > meaningless to the shell

echo help | sendmail '<isp-mailhost.domain:user@hostname.domain>'

        # watch /var/adm/messages # press CTRL-C to interrupt tail -f filename

        ping news-digests.mit.edu       # we're both online
        echo help | sendmail majordomo@news-digests.mit.edu 
        mailq
        sendmail -q                     #  send it NOW
        mailq

        # DONE #

Because Slackware selected the dns sendmail.cf, and didn't defined any SMART_PATH, sendmail will attempt to call news-digests.mit.edu DIRECTLY. Sendmail uses DNS to get the most direct route.

If the modem is DOWN, your dns link will be down. Sendmail won't be happy. It may decide that it can't queue this for later, and bounce it back at you immediately.

If you remain on-line, mit.edu will reply directly to you. If you go off-line, your reply will be sent to your 'backup' mailhost. IE your ISP's mailhost, which will store it for 6 weeks or whatever.

You may need to run a command to tell your isp-mailhost you want to download now. I use finger @mailhost, your ISP will have told you what to do.

If you have POP instead of plain SMTP, your story may be different.

14.9 Sendmail Documentation

Remember that mc-3.1 can read groff formatted documents using the F3 key, without it you would need groff -Tascii -me op.me

  DOCS
        /usr/src/sendmail/cf/README - text lists many macros and names
        /usr/src/sendmail/cf/README.linux - the two Slackware .mc files
        /usr/src/sendmail/README.linux - the two Slackware .mc (different)
        /usr/doc/sendmail/op/op.me - operators manual 
        /usr/doc/sendmail/FAQ -
 -->    /usr/doc/sendmail/READ_ME - main README - lists most other docs

  DEMOS
        /usr/src/sendmail/cf/cf/tcpproto.mc
  MAN PAGES and apps
        mailaddr(7)
        procmail
        sendmail
        deliver
        (Write your list here)
  USENET
        comp.mail.sendmail


Previous Next Table of Contents