From vWiki
Jump to navigation Jump to search

Sendmail is an old SMTP server application. Those in the know generally seem to prefer either Exim or Postfix, but sendmail is still included by default in many Linux distributions, so you tend you end up using sendmail by default. Whilst sendmail is highly configurable, its not the easiest to configure.



By default, sendmail will send emails direct to the receiving MTA/email server. However, you can force it to send via another server (a mime server for example).

Edit the config file - /etc/mail/, and add IP or name of the SMTP server you want to send to...

# "Smart" relay host (may be null)

If you need/want to use a hostname...

# "Smart" relay host (may be null)

Restart the service, and test

service sendmail restart


Out of the box, sendmail allows for some generous time-outs. It really wants to deliver mail on the first attempt. However, you may prefer to deliver what you can quickly, and leave mail destined for slower receivers to be delivered later. For example if you need to handle bursts of messages, and where the sending system(s) need(s) to be freed up as soon as possible.

Edit the config file - /etc/mail/,

# timeouts (many of these)
O Timeout.iconnect=5s
O Timeout.mail=5m
O Timeout.datainit=2m

Restart the service, and test

service sendmail restart

Taken from the recommendations at

Allowed/Denied Senders/Receivers

First check that the feature is enabled in, look in (don't worry about a dnl at the end of the lines, only if they're at the front)


You can then edit the access to allow or deny email, eg

# Allow connections from (relaying) from the following...
Connect:localhost.localdomain           RELAY
Connect:localhost                       RELAY
Connect:                       RELAY
Connect:192.168.10                      RELAY

# Deny email destined for recipients                       550 Mail relay disabled for this recipient                        550 Mail relay disabled for this recipient


Process Queue

 sendmail -v -q

Performs a queue process run

Queue Size

sendmail -bp

or if sendmail's queued emails are residing in /var/spool/mqueue...

find /var/spool/mqueue -type f -name qf\* -print|wc -l|tr -d ' '

Send Test Email

From Local Server

From the local server, you test by creating a text file with the email contents (eg /tmp/testmail)..

Subject: Test email via sendmail
From: your-server

Some content

...and then send using...

sendmail -vt < /tmp/testmail

From Remote Server

You can use telnet, but not from a Windows server (it just doesn't seem to work, use blat instead). Replace the IP address with that of your server...

telnet 25
MAIL FROM:your-server
Subject: Test email via sendmail
Some text for the email

Find Email To/From Email/IP Address

Use the following script to extract all traffic for a particular email or IP address


# Search for all mail for an IP address or mail address
# Usage maillog-analyse <search-for-this> <in-this-log>
# EG ./maillog-analyse /var/log/maillog
# EG ./maillog-analyse /var/log/maillog.2

#echo "Searching for traffic for $1 in $2"

for i in `grep -i $1 $2 | awk '{print $6}' | sed 's/\://'`
    do grep -i $i $2

So, if you save the script as maillog-analyse, run as follows to send to the output to a file

./maillog-analyse /var/log/maillog.1 >maillog-filtered
./maillog-analyse /var/log/maillog >maillog-filtered