Sendmail
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.
Configuration
Relay
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/sendmail.cf
, and add IP or name of the SMTP server you want to send to...
# "Smart" relay host (may be null) DS[10.0.226.60]
If you need/want to use a hostname...
# "Smart" relay host (may be null) DSsmtp.domain.com
Restart the service, and test
service sendmail restart
Time-Outs
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/sendmail.cf
,
# 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 http://www.trilug.org/~jonc/mailserver/PartIII.html
Allowed/Denied Senders/Receivers
First check that the feature is enabled in sendmail.mc
, look in (don't worry about a dnl
at the end of the lines, only if they're at the front)
FEATURE(access_db) FEATURE(blacklist_recipients)
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:127.0.0.1 RELAY Connect:192.168.10 RELAY # Deny email destined for recipients server.domain.com 550 Mail relay disabled for this recipient user@another.com 550 Mail relay disabled for this recipient
Troubleshooting
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
)..
To: you@domain.com 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 192.168.10.11 25 HELO domain.com MAIL FROM:your-server RCPT TO:you@domain.com DATA 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
#!/bin/bash
# Search for all mail for an IP address or mail address
# Usage maillog-analyse <search-for-this> <in-this-log>
# EG ./maillog-analyse 69.57.250.252 /var/log/maillog
# EG ./maillog-analyse somejoe@domain.com /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
done
So, if you save the script as maillog-analyse
, run as follows to send to the output to a file
./maillog-analyse 125.57.250.252 /var/log/maillog.1 >maillog-filtered ./maillog-analyse someone@domain.com /var/log/maillog >maillog-filtered