.:The Tube:. The Tube

Sendmail, Courier-IMAP (Maildrop) mit Virtuellen Mailboxen auf OpenBSD

Einführung

Dieses Crash Tutorial zeigt Dir wie man ein Virtuele Mailboxen mit Sendmail, Courer-IMAP und Maildrop OpenBSD einrichtet. Getestet wurde dieses Tutorial mit OpenBSD 3.6 und einem Pentium2
Falls Du fragen oder anregungen hast kannst Du mir jederzeit ein Mail schreiben (tutorial@thetube.ch).

1. Was es dazu braucht :

2. Szenario :

Bei diesem HowTo wird auf ein LDAP Server verzichtet! Es eignet sich also nur für kleinere umgebungen. Auf eine Authentifizierung mit SSL/TSL wurde verzichtet!
Dieses Tutorial eignet sich wenn Ihr z.B. ein Groupware Programm auf der selben Kiste installiert. Der erste teil des Tutorials (IMAP) wurde von Daniel Tams übernommen und modifiziert! Ihr findet bei den Referenzen der Link des Original Tutorials!

3. Courier IMAP Installieren :

# pkg_add -v ftp://ftp.openbsd.org/pub/OpenBSD/3.6/packages/i386/courier-imap-3.0.5.tgz

Beispiel Konfigs kopiere
# cp -R /usr/local/share/examples/courier-imap/ /etc/

Editiert imapd in /etc/courier-imap
##VERSION: $Id: imapd.dist.in,v 1.29 2004/04/18 15:54:39 mrsam Exp $
ADDRESS=0
PORT=143
MAXDAEMONS=40
MAXPERIP=4
PIDFILE=/var/run/imapd.pid
TCPDOPTS="-nodnslookup -noidentlookup"
AUTHMODULES="authdaemon"
AUTHMODULES_ORIG="authdaemon"
DEBUG_LOGIN=0
IMAP_CAPABILITY="IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA AUTH=PLAIN IDLE"
IMAP_KEYWORDS=1
IMAP_CAPABILITY_ORIG="IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA AUTH=CRAM-MD5 AUTH=CRAM-SHA1 IDLE"
IMAP_IDLE_TIMEOUT=60
IMAP_CAPABILITY_TLS="$IMAP_CAPABILITY AUTH=PLAIN"
IMAP_CAPABILITY_TLS_ORIG="$IMAP_CAPABILITY_ORIG AUTH=PLAIN"
IMAP_DISABLETHREADSORT=0
IMAP_CHECK_ALL_FOLDERS=0
IMAP_OBSOLETE_CLIENT=0
IMAP_ULIMITD=65536
IMAP_USELOCKS=1
IMAP_SHAREDINDEXFILE=/etc/courier-imap/shared/index
IMAP_ENHANCEDIDLE=0
IMAP_TRASHFOLDERNAME=Trash
IMAP_EMPTYTRASH=Trash:7
IMAP_MOVE_EXPUNGE_TO_TRASH=0
SENDMAIL=/usr/sbin/sendmail
HEADERFROM=X-IMAP-Sender
IMAPDSTART=NO
MAILDIRPATH=Maildir

Editiert authdaemonrc in /etc/courier-imap
##VERSION: $Id: authdaemonrc.in,v 1.8 2001/10/07 02:16:22 mrsam Exp $
authmodulelist="authcram authuserdb"
authmodulelistorig="authcustom authcram authuserdb authldap authpgsql authmysql authpwd"
daemons=5
version=""
authdaemonvar=/var/run/courier-imap

Nun bereiten wir die Virtuellen Usermailboxes vor. Zuert legen wir einen User vmail an und eröffen das Directory für die Virtuellen Mailboxen.
# useradd -d /var/vmail -g =uid -s /sbin/nologin vmail
# mkdir /var/vmail
# chown vmail.vmail /var/vmail

Checkt welche UID und GID euer vmail user hat.
# id vmail
uid=1001(vmail) gid=1001(vmail) groups=1001(vmail)

Eröffnet in /etc eine Datei mit dem Namen userdb und editiert diese (Als uid und gid müsst ihr eure uid bzw. gid vom user vmail nehmen!
vmail   uid=1001|gid=1001|home=/var/vmail
1001=   vmail

Mach nun ein chmod auf dieser Datei
# chmod 600 /etc/userdb

Wenn Ihr nun einen Virtuellen User anlegen wollt könnt Ihr folgendes Script brauchen :
(Am besten unter /usr/local/sbin/cour_userdb_mkuser speichern)
#!/bin/sh
MAILDIRMAKE=/usr/local/bin/maildirmake
MAKEUSERDB=/usr/local/bin/makeuserdb
USERDBPW=/usr/local/bin/userdbpw
USERDB=/usr/local/bin/userdb
VUSER=vmail
VUSER_UID=`id -u $VUSER`
VUSER_GID=`id -g $VUSER`
VUSER_HOME=~vmail
NEW_USER=$1

	if [ -z "$NEW_USER" ] then
		echo "Usage:" `basename $0` "<username>"
		echo "Ex: `basename $0` bob"
		exit 1
	fi

# Make sure the user does not already exist.
	if [ -d $VUSER_HOME/Maildir-$NEW_USER ] then
		echo "Error: Account" $NEW_USER "already exists."
		exit 1
	fi

# Create the user's home and mail directory.
echo "Creating a Maildir for" $NEW_USER
$MAILDIRMAKE $VUSER_HOME/Maildir-$NEW_USER

	if [ $? != 0 ]; then
		echo "Error creating Maildir..."
		exit
	fi

chown -R $VUSER.$VUSER $VUSER_HOME/Maildir-$NEW_USER

# Add the user to the proper userdb and set the user's password.
echo "Adding" $NEW_USER "to" /etc/userdb
echo "Enter the password for" $NEW_USER

$USERDBPW | $USERDB -f /etc/userdb $NEW_USER set uid=$VUSER_UID gid=$VUSER_GID home=$VUSER_HOME mail=$VUSER_HOME/Maildir-$NEW_USER
$USERDBPW -md5 | $USERDB -f /etc/userdb $NEW_USER set systempw

# Make sure the new user is noticed.
$MAKEUSERDB

# Finalize for user.
echo
echo " Done!!! $NEW_USER has been added to Courier-IMAP."
echo
exit 0

4. Maildrop :

Maildrop installieren
# pkg_add -v ftp://ftp.openbsd.org/pub/OpenBSD/3.6/packages/i386/maildrop-1.5.3.tgz

5. Sendmail :

Neue Konfig Datei erzeugen und Kompilieren :
# cd /usr/share/sendmail/cf
# cp openbsd-localhost.mc openbsd-example.mc

openbsd-example ergänzen :
divert(-1)
#
# Copyright (c) 1998 Sendmail, Inc.  All rights reserved.
# Copyright (c) 1983 Eric P. Allman.  All rights reserved.
# Copyright (c) 1988, 1993
#       The Regents of the University of California.  All rights reserved.
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the sendmail distribution.
#
#

#
#  This configuration only runs sendmail on the localhost interface.
#  This allows mail on the local host to work without accepting
#  connections from the net at large.
#

divert(0)dnl
VERSIONID(`@(#)openbsd-localhost.mc $Revision: 1.4 $')
OSTYPE(openbsd)dnl
FEATURE(`virtusertable', `hash /etc/mail/virtusertable')
FEATURE(use_cw_file)
FEATURE(`local_procmail',`/usr/local/bin/maildrop',`maildrop -d $u')
FEATURE(nouucp, `reject')dnl
FEATURE(`accept_unresolvable_domains')dnl
FEATURE(`no_default_msa')dnl
MAILER(local)dnl
MAILER(smtp)dnl
DAEMON_OPTIONS(`Family=inet, address=0.0.0.0, Name=MTA')dnl
DAEMON_OPTIONS(`Family=inet6, address=::, Name=MTA6, M=O')dnl
DAEMON_OPTIONS(`Family=inet, address=0.0.0.0, Port=587, Name=MSA, M=E')dnl
DAEMON_OPTIONS(`Family=inet6, address=::, Port=587, Name=MSA6, M=O, M=E')dnl
CLIENT_OPTIONS(`Family=inet6, Address=::')dnl
CLIENT_OPTIONS(`Family=inet, Address=0.0.0.0')dnl
dnl
dnl Some broken nameservers will return SERVFAIL (a temporary failure)
dnl on T_AAAA (IPv6) lookups.
define(`confBIND_OPTS', `WorkAroundBrokenAAAA')dnl
LOCAL_RULESETS
HMEssage-Id: $>CheckMessageId

SCheckMessageId
R< $+ @ $+ >            $@ OK
R$*                     $#error $: 553 Header Error

Konfigdatei Kompilieren
# m4 ../m4/cf.m4 openbsd-example.mc > openbsd-example.cf

Konfigdatei in /etc/mail kopieren
# cp openbsd-example.cf /etc/mail/

die openbsd-example.cf in /etc editieren
cd /etc/mail
vi openbsd-example.cf

Nun wird das w gelöschen bei
 
(Mlocal,         P=/usr/local/bin/maildrop, F=lsDFMA5:)

Sendmail neu starten
# kill -15 `head -1 /var/run/sendmail.pid`
# sendmail -L sm-mta -C /etc/mail/openbsd-example.cf -bd -q30m

6. Virtueller User eröffnen :

Für einen neuen User anzulegen braucht das Script
/usr/local/sbin/cour_userdb_mkuser benny

Virtueller User in der /etc/mailvirtusertable bei sendmail hinzufügen
# $OpenBSD: virtusertable,v 1.2 2004/01/13 15:43:40 millert Exp $
#
# sendmail(8) virtual user table.  Rebuild by running as root:
#   makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
#
# This file contains the mapping of virtual to local addresses.
# Each line denotes a transform of:
#   virtual_address     local_address
#
# E.g.
#   info@foo.com        foo-info
#   info@bar.com        bar-info
#   @baz.org            jane@example.net
#
# It is also possible to map all users from one domain to another, e.g.
#   @foo.org            %1@example.com
#
# See the "virtusertable" section of /usr/share/sendmail/README for
# more information.
#
benny@example.ch	benny

Danach ein makemap ausführen
# makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable

7. Starten :

Starten wir nun der courier-imap server
# /usr/local/libexec/imapd.rc start

Wenn alles gut ging könnt Ihr ein Telnet auf den IMAP machen
# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA AUTH=PLAIN IDLE ACL ACL2=UNION] Courier-IMAP ready. Copyright 1998-2004 Double Precision, Inc.  See COPYING for distribution information.

8. Automatisch bei jedem Boot starten :

Datei /etc/rc.conf.local ergänzen :
courierimap_flags=""

Datei /etc/rc.local ergänzen
if [ X"${courierimap_flags}" != X"NO" ]; then
        mkdir -p /var/run/courier-imap
        echo -n ' courier-imap';                /usr/local/libexec/imapd.rc start ${courierimap_flags}
fi

Referenzen

  1. OpenBSD Seite — Offizielle OpenBSD Seite
  2. UnixScout Seite — Jede Menge HowTo's!
  3. Courier-IMAP Seite — Offizielle Courier-IMAP Homepage
  4. MailDrop Seite — Offizielle Maildrop Homepage
  5. Courier-IMAP Tutorial mit SSL/TLS — Daniel Tams Courier-IMAP HowTo
Zurück