# Sendmail

Test makefile:

CFDIR=/usr/share/sendmail

start: test.cf database
	sendmail -L sm-mta -C/etc/mail/test.cf -q30m -bD -OLogLevel=65

test.cf::
	m4 -DSASL ${CFDIR}/m4/cf.m4 test.mc > test.cf

access.db::
	makemap hash /etc/mail/access < /etc/mail/access

domaintable.db::
	makemap hash /etc/mail/domaintable < /etc/mail/domaintable

mailertable.db::
	makemap hash /etc/mail/mailertable < /etc/mail/mailertable

virtualuser.db::
	makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable

authinfo.db::
	makemap hash /etc/mail/authinfo < /etc/mail/authinfo

userdb.db::
	makemap btree /etc/mail/userdb < /etc/mail/userdb

sasldb2.db::
	makemap hash /etc/mail/sasldb2 < /etc/mail/sasldb2

database:: access.db domaintable.db virtualuser.db mailertable.db userdb.db sasldb2.db

clean:
	rm test.cf

# Queuing

# Aliases

# VirtualHost

# Masquerading

# Sendmail Configuration File (sendmail.m4)

TIP

You should read /usr/share/sendmail/cf/README file.

export CFDIR=/usr/share/sendmail/cf
m4 -D_CF_DIR_=${CFDIR}/ ${CFDIR}/m4/cf.m4 config.mc > config.cf

# VERSIONID

defined in m4/version.m4 and define the version based on RCS, CVS... This is not the one set in the protocol itself.

# OSTYPE

TODO

# DOMAIN

TODO

# MAILER

TODO

# Sendmail Configuration File (sendmail.cf)

name term definition
rule R rewrite addresses from an address to another
rule set S control rewrite steps
mail delivery agent M call another program for delivery
define macros D define a configuration macro
class macros C or F
database K look information from database
options O set command line options
header H set the mail header
milters X set and configure a milter (external program hook)

# Rules configuration

This simple snippet can help you to test the rule you are creating in .cf configuration files.

SENDMAIL_CONF=""
_test() {
    if [ "${SENDMAIL_CONF}" ]
    then
        echo $* |  /usr/sbin/sendmail -bt -C ${SENDMAIL_CONF}
    fi
}

To use it, you can, for example, define a new rule in test.cf file.

Stest
R $-    garbage@test.com
R $+@test.net   $1@test.com

Set the variable.

export SENDMAIL_CONF=${PWD}/test.cf

Test the second rule, when using pattern matching $+@test.net.

_test test test@test.net
# ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
# Enter <ruleset> <address>
# > test               input: test @ test . net
# test             returns: test $@ test . com

Test the first rule, when only one token is present by using $- parameter.

_test bar
# ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
# Enter <ruleset> <address>
# > test               input: bar
# test             returns: garbage @ test . com

# Security

# Authentication (SASL)

WARNING

SASL authentication need to have access to saslpasswd2 command. This tool is available through cyrus-sasl2 (opens new window) package.

saslpasswd2 ${username}

Here a snippet to test the challenge

% R24 code
cram_md5(User, Key, Challenge) ->
  DecodedChallenge =  base64:decode(Challenge),
  EvalChallenge = binary:encode_hex(crypto:mac(hmac, md5, Key, DecodedChallenge)),
  CleanChallenge = string:lowercase(EvalChallenge),
  EncodeResult = base64:encode(User/bitstring, " ", CleanChallenge/bitstring>>),
  <<EncodeResult, "\n">>.

% R24 lambda one line
F = fun(U, K, D) -> 
  T = string:lowercase(binary:encode_hex(crypto:mac(hmac, md5, K, base64:decode(D)))),
  R = base64:encode(<<U/bitstring, " ", T/bitstring>>),
  <<R/bitstring, "\n">> 
end.

# Trusted Users

define(`confTRUSTED_USERS',`root')

On FreeBSD, you can see this configuration:

#Ft/etc/mail/trusted-users
Troot
Tdaemon
Tuucp

# Privacy settings

define(`confPRIVACY_FLAGSĀ“, `goaway,restrictmailq,restrictqrun')

where:

  • goaway

  • restrictmail

  • restrictqrun

# Debugging

TIP

This table is coming from op.me file present in contrib/sendmail/doc/op/op.me on FreeBSD source tree. This file can be compiled in txt, pdf or postscript file.

level comment
0 Minimal logging
1 Serious system failures and potential security problems
2 Lost communications
3 Other serious failures
4 Minor failures
5 Message collection statistics
6 Creation of error messages
7 Delivery failures
8 Successful deliveries
9 Messages being deferred
10 Database expansion and authentication information
11 NIS errors
12 all SMTP connections
13 bad user shells, files with improper permissions
14 refused connections
15 all incoming SMTP commands
20 attempts to run locked queue files
30 Lost locks
>64 extremely verbose debugging output
sendmail -Ctest.cf -q30m -bD -OLogLevel=64

# Tracing

TIP

All debugging numbers and flags can be found in sendmail/TRACEFLAGS file from source code. On FreeBSD, this file is available in contrib/sendmail/srv/TRACEFLAGS (opens new window)

By using -d flag, it is possible to print different kind of information. Flags can be added separated by commas. You can use both integer or term for the first element of the debugging pattern. The second pattern is an integer. Here the table for the log levels:

Print version and exit:

sendmail -bD -v -d0.1

Show connection used by daemons:

sendmail -bD -v -d15.10,16.10

# Procmail Configuration

# Dovecot Configuration

# Maildrop Configuration

# Spampd Configuration

# References and Resources

# Source Code

# Websites