WheezyのLDAPアカウントでメール送受信

■Postfixを導入、初期設定

$ sudo apt-get install -y postfix
$ sudo dpkg-reconfigure postfix

■転送用のファイルの作成

$ hostname -f
lpic3.openldap.local

$ echo "openldap.local:[lpic3.openldap.local]
.openldap.local:[lpic3.openldap.local]
" | sed s/":"/"\t\t\t:"/g | sudo tee /etc/postfix/transport
openldap.local                  :[lpic3.openldap.local]
.openldap.local                 :[lpic3.openldap.local]

$ sudo postmap /etc/postfix/transport

■転送用のファイルの読み込みの設定

$ sudo sed s%"alias_maps"%"transport_maps = hash:/etc/postfix/transport\n&"% /etc/postfix/main.cf | \
  grep -A 1 ^transport
transport_maps = hash:/etc/postfix/transport
alias_maps = hash:/etc/aliases

$ sudo sed -i s%"alias_maps"%"transport_maps = hash:/etc/postfix/transport\n&"% /etc/postfix/main.cf
$ sudo postfix check && sudo /etc/init.d/postfix restart

■UNIXアカウントでの送受信
 Solarisだと「stat=Sent」だったかな?にも対応するようにというどうでもいいことをしつつ。。。

$ echo "test" | mail -s "test" `whoami`@openldap.local
$ sudo tail -5 /var/log/syslog | grep -i "sta.*=sent" | sed s/"\: \|,"/"&\n"/g
Apr 27 23:40:50 lpic3 postfix/local[13811]:
CC9C9889E1:
to=<labunix@openldap.local>,
 relay=local,
 delay=0.01,
 delays=0/0/0/0.01,
 dsn=2.0.0,
 status=sent (delivered to command:
procmail -a "$EXTENSION")

■ldapuserでの送受信

$ echo "test" | mail -s "test" ldapuser@openldap.local
$ mail
Mail version 8.1.2 01/15/2001.  Type ? for help.
"/var/mail/ldapuser": 1 message 1 new
>N  1 ldapuser@lpic3.op  Sun Apr 28 02:08   14/505   test

$ sudo tail -5 /var/log/syslog | grep -i "sta.*=sent" | sed s/"\: \|,"/"&\n"/g
Apr 28 02:08:14 lpic3 postfix/local[5365]:
6D1183FF94:
to=<ldapuser@openldap.local>,
 relay=local,
 delay=0.05,
 delays=0.02/0.01/0/0.01,
 dsn=2.0.0,
 status=sent (delivered to command:
procmail -a "$EXTENSION")

■別のlinuxサーバから接続

$ telnet openldap.local 25
Trying 192.168.1.1...
Connected to lpic3.openldap.local.
Escape character is '^]'.
220 lpic3.openldap.local ESMTP Postfix (Debian/GNU)
ehlo localhost
250-lpic3.openldap.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:ldapuser
250 2.1.0 Ok
rcpt to:ldapuser@openldap.local
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subect: Test

Hello World
.
250 2.0.0 Ok: queued as 8A4C640171
quit
221 2.0.0 Bye
Connection closed by foreign host.

■sshでもログインできるのだし、
 システムメールを使う分にはldapモジュールは無くても良いようだ。
 後は「transport」に設定してあげればよい。

$ sudo postconf -m | grep ldap
$ apt-cache show postfix-ldap | grep ^Version
Version: 2.9.6-2

■dovecotの導入
 Thunderbirdのセキュリティの例外(有効期限10年の自己証明書)を承認することで
 UNIXアカウント、ldapuserアカウントの両方で送受信ができることを確認。

$ sudo apt-get install -y dovecot-pop3d
...
reating generic self-signed certificate: /etc/dovecot/dovecot.pem
This certificate will expire in 10 years.
(replace with hand-crafted or authorized one if needed).
[ ok ] Starting IMAP/POP3 mail server: dovecot.
dovecot-pop3d (1:2.1.7-7) を設定しています ...

Creating config file /etc/dovecot/conf.d/20-pop3.conf with new version
[ ok ] Restarting IMAP/POP3 mail server: dovecot.

■Postfixのldapモジュールを使った連携については以下を参照

 Postfix LDAP Howto
 http://www.postfix-jp.info/trans-2.1/jhtml/LDAP_README.html