Sendmail

From vwiki
Revision as of 10:45, 19 November 2013 by Sstrutt (talk | contribs) (→‎Configuration: Added "Allowed/Denied Senders/Receivers")
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.

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

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
.