Postfix tips
Postfix freebsd cron problem
Once you install postfix on your freebsd box, you might notice the following
problem.
In /var/log/maillog:
Jul 20 00:35:00 jenova postfix/sendmail[49605]: fatal: munin(842): No recipient addresses found in message header
In /var/log/cron:
Jul 20 11:05:00 jenova cron[53366]: NSSWITCH(_nsdispatch): nis, passwd_compat, endpwent, not found, and no fallback provided
Edit /etc/nsswitch.conf
group: files
passwd: files
Send a mail using telnet
Send a mail using telnet
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 jenova.nogafa.org ESMTP Postfix (NOGAFA)
helo www.com
250 jenova.nogafa.org
mail from: test1234@nogafa.org
250 2.1.0 Ok
rcpt to: test1234@nogafa.org
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test1807
.
250 2.0.0 Ok: queued as 54A2D5E0002E
quit
221 2.0.0 Bye
Connection closed by foreign host.
Test tls with openssl
openssl s_client –tls1_3 -starttls smtp -crlf -connect 127.0.0.1:587
Postfix related
Several add-on software are necessary to get a fully functionnal mail
server. Describing all of them here would take too long, therefore I’ll
try to tell about the ones I use that are not very common.
getmail
The program getmail is a simple mail
retriever, a good alternative to fetchmail. It’s written in Python and
licensed under GPLv2.
Key features (complete list)
Installing from ports on FreeBSD:
cd /usr/ports/mail/getmail && make install clean
As a regular user, edit or create the configuration file .getmail/getmailrc:
[retriever]
type = SimplePOP3Retriever
server = pop.myotherprovider.com
username = mylogin
password = mypass
[destination]
type = Maildir
path = ~mylocaluser/Maildir/
The previous file contains passwords in plain text, so change it’s permissions:
chmod 600 ~mylocaluser/.getmail/getmailrc
Test it:
$getmail -nl
getmail version 4.20.0
Copyright (C) 1998-2009 Charles Cazabon. Licensed under the GNU GPL version 2.
SimplePOP3Retriever:mylogin@pop.myotherprovider.com:110:
msg 1/1 (1394 bytes) delivered
1 messages (1394 bytes) retrieved, 0 skipped
Use it (once you are REALLY sure! Make copy/backup of your mail before!):
$getmail -ad
getmail version 4.20.0
Copyright (C) 1998-2009 Charles Cazabon. Licensed under the GNU GPL version 2.
SimplePOP3Retriever:mylogin@pop.myotherprovider.com:110:
msg 1/1 (1402 bytes) delivered, deleted
1 messages (1402 bytes) retrieved, 0 skipped
Schedule it, for example using mylocaluser’s crontab every 5 minute:
$crontab -e
*/5 * * * * /usr/local/bin/getmail -ad > /dev/null 2>&1
That’s it. Others similar tools you might be looking for are imapsync and
fetchmail.
maildrop
The program maildrop is what we call
(in the obfuscated sysadmin slang) a MUA. It’s job is to recieve mail from an
MTA (postfix) and deliver it to local user (who called them luser at this
point? They don’t always run m$ Outhouse :) ).
Even if maildrop is part of courier suite, it can be installed as a standalone
product. It’s written in C++, licensed under GPL and supports both mbox and
Maildir.
We assume the following scenario
No virtual user nor virtual domain (postfix acception)
Users have write access (ssh, ftp, sftp, svn, web api …) to their home directory or they won’t be able to filter their mail serverside.
Maildir format is used instead of mbox.
Installing from ports on FreeBSD:
cd /usr/ports/mail/maildrop && make install clean
Configure postfix to use maildrop as a MDA in /etc/postfix/main.cf:
mailbox_command = /usr/local/bin/maildrop -d ${USER}
Here’s a minimal maildroprc file:
DEFAULT = "$HOME/Maildir"
DEFAULT = "$HOME/Maildir"
logfile "/var/log/maildrop/maildrop.log"
If you need to set to system-wide options for maildrop, you can edit
/usr/local/etc/maildroprc. Otherwise, for each regular user, edit
~mylocaluser/.mailfilter
MAILDIR="/home/mylocaluser/Maildir"
if (/^List-Post: <mailto:freebsd-current@freebsd.org>$/)
to $MAILDIR/.list
if (/^List-Post: <mailto:varnish-misc@varnish-cache.org>$/)
to $MAILDIR/.list
Why should I use MUA like maildrop or procmail while postfix knows how to
deliver mail to both mbox and Maildir? Well, I don’t know about your needs but
I felt very confortable without MUA until I subscribed a few mailing lists and
wanted my mail to be sorted automatically. There are various other ways to
achieve this, like using mutt in a screen or cyrus with sieve.
By the way, to use postfix as MDA with Maildir format, just edit /etc/postfix/main.cf:
sieve
test via cli
sieve-filter -v -C -u user@dn.tld /home/user/vmail/dn/user/.dovecot.sieve 'INBOX'
test via cli
sieve-filter -v -C -e -W -u user@dn.tld /home/user/vmail/dn/user/.dovecot.sieve 'INBOX'
pflogsumm
No postfix server should be installed with pflogsumm. It’s a mere perl script designed
to parse postfix logs and output a neat repport.
Installing from ports on FreeBSD:
cd /usr/ports/mail/pflogsumm && make install clean
Use it:
bzcat /var/log/maillog.0.bz2 |pflogsumm
Enjoy the result:
Grand Totals
------------
messages
110 received
110 delivered
0 forwarded
0 deferred
0 bounced
34 rejected (23%)
0 reject warnings
0 held
0 discarded (0%)
543k bytes received
543k bytes delivered
11 senders
7 sending hosts/domains
8 recipients
4 recipient hosts/domains
... ... ...