17. Sendmail - more to play with

If sendmail now works, fine. But if you want to do some experimenting, you may want a few scripts to help you, ie a script that sends a test message, just by running it.

You might also prefer to use an /etc/sendmail.mc file that has more comments in it, but still want a condensed version, with just the content in it.

Here are a few scripts that may help. I put them in /home/gps/bin, which is on may $PATH. Don't forget to chmod 755 script.

If you use X11 CUT+PASTE, you will be pasteing several spaces instead of a single TAB. You will have to pay special attention to that. Most of these scripts use [ SP TAB ], but you can't see that.

17.1 no_blank_lines - (chmod 755 /usr/local/bin/no_blank_lines)
17.2 no_comments - a shell script
17.3 no_trail_sp - a shell script
17.4 full_path_name - a shell script to get a full path name
17.5 HINT: Creating documents with CUT and PASTE
17.6 send_11 - a quick test utility
17.7 mc_to_cf - a shell script to install an mc file
17.8 sendmail.mc - with comments looks like:
17.9 /usr/src/sendmail/cf
17.10 ls -l /var/spool/mail/postmaster
17.11 Sendmail site configurations
17.12 Smart Host = LAN gateway
17.13 Smart Host = WAN gateway (ISP)
17.14 ISP smarthost is faster
17.15 ISP smarthost is slower
17.16 One Hop is faster
17.17 Direct is more private

17.1

no_blank_lines - (chmod 755 /usr/local/bin/no_blank_lines)

#!/bin/sh
# here blank lines includes TAB or SP
# elsewhere they indicate non-blank lines!

grep -v '^[	 ]*$'

# eof # no_blank_lines

This script removes all blank lines. It reads from it's STDIN and writes to STDOUT.

17.2

no_comments - a shell script

#!/bin/sh
# [] - can be hard to see and read
# provides a very simplistic definition of 'comment'
# works with terminfo source and lots else
# '#' must be at the start of a line, or preceded by BLANK(s)
# messes up line numbers
# no protection of # 'eg # in quotes'
# [	 ] is TAB SPACE in square brackets.

grep -v '^#' "$@" | sed 's,[	 ][	 ]*#.*,,'

# eof # no_comments #
This script removes comments. A comment must have at least one space or tab before the # character, or have the # at the start of the line.

17.3

no_trail_sp - a shell script

#!/bin/sh
# removes spaces from the end of lines
# [] - can be hard to see and read

sed s,[	 ]*$,,

17.4

full_path_name - a shell script to get a full path name

#!/bin/sh
[ $# = 1 ] || exit 1

if expr match "$1" /  >/dev/null
then
	echo "$1"	# already absolute
else
	echo `pwd`/"$1"
fi
		
# eof # full_path_name #

This script outputs an absolute pathname, by prefixing it with `pwd` (unless it already is an absolute pathname). This then enables you to cd elsewhere.

17.5

HINT: Creating documents with CUT and PASTE

If you manually type in these examples (or others), be careful to get them right. You can save yourself a bit of work by using CUT and PASTE, but do be careful that special characters, such as TAB haven't been converted to spaces!

With X11, highlight the text selection, by dragging with the left button over the text. Then use the RIGHT mouse button to paste it into a different window.

If the other window is xterm (eg running vi), remember to press SHIFT to tell xterm tu feed it via the keyboard channel, and also make sure that vi (or whatever) is in INSERT mode, otherwise the characters will be seen as key-commands, not typed text! (vi has a command for almost every letter!)

gpm does a similar job on text consoles. So you can use lynx, or copy from the .txt files. You can switch consoles and paste the text there.

If you don't like VI, you can try pico the editor from the PINE package. It is very simple, and looks a bit strange, outside of PINE, but it works.

When pasting into vi, you might need to switch auto-indent off, otherwise it may staircase, adding the spaces at the start of each line to the next indent! : set noai

17.6

send_11 - a quick test utility

#!/bin/sh
# send a test email to the command line parameter
# used to test sendmail

addr="${1:-user@host.domain}" # default or override

sendmail -t <<-EOT-1 # eof also stops a HERE document zone
To: $addr
Subject: test mail addressed to $addr

	This is a test mail to see what happens
	when mail is sent to the address:
		 $addr
	using sendmail -t
	following dot may end the email
.
	or not!
EOT-1

echo "$0: sendmail $addr returned exit code $?"

# eof # send_11 #

This script shows you how to send an email automatically. The destination has a default, but can be specified on the command line. see man sh(1) for more explanation.

17.7

mc_to_cf - a shell script to install an mc file

#!/bin/sh
# converts .mc to .cf
# removes comments and keeps a minimised copy
# uses other scripts listed here
[ $# = 1 ] || exit 1

file=`full_path_name $1`
cd /usr/src/sendmail/cf		# normal location of file
no_comments $file 	\
| no_trail_sp		\
| no_blank_lines	\
| tee $file.no_com 	\
| m4 			\
> /etc/sendmail.cf

# some pople use:  mv /tmp/sendmail.cf /etc/sendmail.cf
# incase of fail half way through

killall sendmail	# still using old .cf file ?
mailq			# view queue before starting
sendmail -bd -q 15m
Now you can make your sendmail.mc file executable. Running it installs it as the new configuration. That makes it easy to edit and test (you must be root to do this). Now your sendmail.mc file might look like:

17.8

sendmail.mc - with comments looks like:

So now you can write a sendmail.mc file, that contains comments, and even stray spaces at the end of the line. See also /usr/src/sendmail.

#!/usr/local/sbin/mc_to_cf
# the above line makes this an executable script
# with chmod 755 of course
# gets pre-processed by me then m4 to the .cf file

# divert(-1) is an m4 thing
divert(-1)

# include the sendmail V8 MACRO framework
include(`../m4/cf.m4')

# tell the reader where this came from
# which host it is intended for
VERSIONID(`my_file.mc - ravens config circa 96 ')

# list of hostnames that sendmail will accept email for
Cwlocalhost trix.lan67.priv trix.dircon.co.uk

# declare gateway or ISP machine
define(`SMART_HOST', mailhost.dircon.co.uk )

# Linux file layout FSSTND
OSTYPE(linux)

# 'uucp' is an overloaded term, often running over smtp!
# 'uucp' predates TCP/IP (it is an rs232 modem dialup scheme)
FEATURE(nouucp)

# included anyway!
MAILER(local)

# use big cloud networking, smtp protocol
MAILER(smtp)

# dns seems like a good idea - BUT -
FEATURE(nodns)

17.9

/usr/src/sendmail/cf

Compare this mail-conf-script with those in /usr/src/sendmail/cf. They are all much the same, with hardware names to make Linux users feel at home, or 'hp' users get the 'correct' pathnames. If you plough through them you may find interesting cases that handle BITNET to Internet to UUCP gateways, or categories of gateway types, and hosts within a gateway's 'domain' (an ambiguous word).

What are those configurations in /usr/src/sendmail/cf/? What shape networks are they handling?

17.10

ls -l /var/spool/mail/postmaster

Check this file rgularly, sendmail sends error rports here. Eg if someone send mail to wrong_name@host.domain, they get a fail message, postmaster gets a copy of the original.

17.11

Sendmail site configurations

Remember that email gateways are different from TCP/IP gateways, though one machine might do both jobs. TCP/IP gateways, are really routers that direct IP packet traffic. EMAIL gateways do much the same, but with email messages, not TCP/IP packets.

The email gateway for a domain, handles incoming traffic bound for all local machines.

If the sender reaches the destination machine (wth TCP/IP:SMTP), the gateway is not used. Email within the domain may be direct, or through the gateway. The gateway expects to receive email addressed to a LIST of hosts, or domains.

A gateway can have a simple name, and route mail to machines in other LAN's, eg user@company.com gets routed to <user@host.lan.building.town,country.company.com>. Then that might be send to a gateway towards that domain. ie CInorder to reach user@host.lan_90.bodmin.uk.company.com, the email gets sent via user@pigeon.demon.co.uk

That routing could be a chain-list of addresses, or it could simply be the nearest gateway to user that would know the proper address.

If you only have a leaf PC connected to an Internet provider, you are a leaf attached to an intelligent gateway - your ISP's mailhost.

17.12

Smart Host = LAN gateway

A LAN of PC's can have peep-to-peer email. The sender has to know which host a user is on (From: user@crow.domain), or the network can be designed so that the sender replies to: user@domain, in which case the email is sent to the server/gateway, which looks up user in a databse to find that the next hop is to (or via) crow.domain.

If the destination address is outside of the LAN, it will probably have to go through a gateway (the gateway), so if the PC can't reach the host directly it simply sends it to the gateway, whhich then has the responsibility of routing it.

17.13

Smart Host = WAN gateway (ISP)

If you have a single PC connected to the Internet via dial_up, all your TCP/IP packets go through your ISP's LAN (possibly 100 M ethernet not 10 M ethernet).

Your ISP will have an internal LAN that connects the various TCP/IP routers, name servers, terminal servers, and service hosts (mailhost, ftp.hosts, www.hosts). It is likely that your ISP have several LAN's all threaded together.

If your packet traffic goes worldwide (as it does), there will be a spiders web of interconnections between ISP providers, LANS at the remote ISP and LANS at the far end.

Each connection requires that the packet be completely read in (eg 1.5K bytes) by the router, and then re-transmitted on the other side of the router (from wire to router to wire). Transmission on a wire shared by several hosts (eg ethernet not point-to-point), may require a wait for free air-time to become available. This is a tiny delay, but can lead to backlogs, where several packets are waiting in a queue to be transmitted next. The ISP side of your modem is a primary example of this, with ftp packets coming from several directions waiting to be transmitted at V34 speeds.

When all of the UK wants to access all of the US, the air-time providers like having a little capacity overload - before they have to swich on extra circuits that they rent from their providers. Statistically backlogs are few and far between - but how much so?

17.14

ISP smarthost is faster

If your ISP has a quality machine, it will be much faster to transfer email between it and you (data throughput), though there will be a total delay of delivery that takes twice as long. If your host completes sooner, it releases memory sooner, reducing swap, makeing your server faster.

If the remote host is overdriven, data throughput may be slow or even break. It makes more sense to let your ISP have that worry. It may even tolerate remote ISP's going offline for a while.

If your smart host has a quality configuration, it will be able to bridge with other TYPES of networks, and know of routes through gateways (or their smart_hosts). That saves you a lot of hassle, you just have to get the compuserve address right, or the JANET address correct, your ISP does the work.

17.15

ISP smarthost is slower

This is great at 3am in 1996, but at 11:30 in 1998 the picture may be totally different. If your mailhost.isp.com is getting old, overdriven, etc you may not be happy with the service.

Similarly, what happens tomorrow and all next week, when the ISP's mailhost goes AWOL? Presumably, they struggle to get basic connectivity back, and dns lookups are still fast and relatively few.

At that time, you would stop using the smar-thost, and start to go directly to the remote ISP's mailhost, or the end host if it is on-line.

17.16

One Hop is faster

if you are running an interactive multi-media discussion with a friend, simultaneously logged-on. One stop EMAIL is faster than 2 or even 3, even it it runs at a slower throughput.

17.17

Direct is more private

in addition, you know your emaail went through the ISP's packet routers, not through the email gateways (and hence onto disk, along with log-files). You trust your ISP, it's unlikely that they will 'tap-into' your lines, but who works for them? (Ususally these people are too busy, too well paid, and email is boring). BUT ...

EG Your ISP may well collect traffic statistics (From_site, To_site, When, N_bytes) that are retained and archived. How would you feel to find out that a debt collection agency had its email summary log, sold on a weekly basis? You would not be told.

Using the SMART_HOST is usually a good idea.