Mailserver: Cyrus IMAP and Sendmail installation

Mailserver: Cyrus IMAP and Sendmail installation

Mailserver: Cyrus IMAP and Sendmail installation 150 150 Roderick Derks

cyrusThis article descibes the configuration of an IMAP server. The software I used was Fedora Core 4, 5 and 6 and Red Hat AS 4.0 and Cyrus Imap. Before you get started it is advisable and really cool to create a (dymanic) DNS service on your network.

Install & Setup

Install (some commands might not be needed on Fedora or are just for Fedora):
# yum install cyrus-imapd
# chkconfig –add cyrus-imapd
# chkconfig –level 2345 cyrus-imapd on
# service cyrus-imapd start
Starting cyrus-imapd: preparing databases… done.         [  OK  ]

[root@galibier ~]# chkconfig –list saslauthd
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
# chkconfig –level 2345 saslauthd on
# service saslauthd start
Starting saslauthd:                                        [  OK  ]

Change password user cyrus

# passwd cyrus
Changing password for user cyrus.
New UNIX password: ********
Retype new UNIX password: ********
passwd: all authentication tokens updated successfully.

Sendmail configuration including SSL

# cd /etc/pki/tls/certs
# make
# vi /etc/mail/

VERSIONID(`Setup for Red Hat Linux – – 20060804′)dnl


define(`confTO_CONNECT’, `1m’)dnl
define(`ALIAS_FILE’, `/etc/aliases’)dnl
define(`STATUS_FILE’, `/var/log/mail/statistics’)dnl
define(`UUCP_MAILER_MAX’, `2000000′)dnl
define(`confUSERDB_SPEC’, `/etc/mail/userdb.db’)dnl
define(`confPRIVACY_FLAGS’, `authwarnings,novrfy,noexpn,restrictqrun’)dnl
define(`confAUTH_OPTIONS’, `A’)dnl
define(`confCACERT_PATH’, `/etc/pki/tls/certs’)dnl
define(`confCACERT’, `/etc/pki/tls/certs/ca-bundle.crt’)dnl
define(`confSERVER_CERT’, `/etc/pki/tls/certs/’)dnl
define(`confSERVER_KEY’, `/etc/pki/tls/certs/’)dnl

dnl #
dnl # RRD: following is needed to use CYRUS IMAP
dnl #
define(`CYRUSV2_MAILER_ARGS’, `FILE /var/lib/imap/socket/lmtp’)dnl

define(`confTO_IDENT’, `0′)dnl

FEATURE(`mailertable’,`hash -o /etc/mail/mailertable.db’)dnl
FEATURE(`virtusertable’,`hash -o /etc/mail/virtusertable.db’)dnl
FEATURE(`access_db’,`hash -T<TMPF> -o /etc/mail/access.db’)dnl


DAEMON_OPTIONS(`Port=smtp, Name=MTA’)dnl
DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s’)dnl


dnl # RRD: following is needed to use CYRUS IMAP
dnl MAILER(procmail)dnl

# m4 /etc/mail/ > /etc/mail/

Add ip adresses or -ranges of machines who are allowed to make a smtp connection to /etc/mail/access
# vi /etc/mail/access            550 Go away and don’t spam us anymore      OK
10.0                                RELAY


# service sendmail stop
Shutting down sendmail:                                    [  OK  ]
Shutting down sm-client:                                    [  OK  ]
# service sendmail start
Starting sendmail:                                               [  OK  ]
Starting sm-client:                                              [  OK  ]

Check current sendmail configuration
# /usr/lib/sendmail -d0.1 -bv

Create mailuser

# cyradm –user cyrus localhost
IMAP Password:> createmailbox user.roderick (ALSO: cm user.roderick)> setaclmailbox user.roderick logon all> quit

Copy mail from other server:

# cd /var/spool/imap/

Did you get an error like this?
Login failed: generic failure at /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/Cyrus/IMAP/ line 118
cyradm: cannot authenticate to server with PLAIN as cyrus
[root@mailserver] tail /var/log/messages
Aug  9 09:00:42 telegraph perl: No worthy mechs found
Aug  9 09:00:44 telegraph saslauthd[1980]: do_request      : NULL password received

Then go back to paragraph: change password user cyrus. 


Restore Mailbox

This is for users that already have a (cyrus) mailbox on another server.

Synchronize the following directories from our source server mailserver01 to mailserver02. Using this command the rights and permissions will be copied too.
[root@mailserver02 ] cd /var/spool/imap/
[root@mailserver02 imap] rsync -avu -e ssh .

Copy the following directories from the old server mailserver01 to mailserver02:
[root@mailserver02 ]scp -r :/var/lib/imap/ /var/lib/imap/

[root@mailserver02 roderick]# su – cyrus
-bash-3.00$ /usr/lib/cyrus-imapd/reconstruct -f -r user.roderick

Configure squatter (mailbox index process)
add the two lines in the cyrus config file in the EVENTS section
# vi /etc/cyrus.conf

  #rrd index aanmaken van de emails dmv squatter
  squatter      cmd=”squatter -r user” period=1440

# su – cyrus
# /usr/lib/cyrus-imapd/squatter -v -r user.roderick

Setup SSL for Cyrus-Imapd

# openssl req -new -x509 -nodes -out /etc/pki/cyrus-imapd/ -keyout /etc/pki/cyrus-imapd/ -days 999
# openssl req -new -x509 -nodes -out /etc/pki/cyrus-imapd/ -keyout /etc/pki/cyrus-imapd/ -days 999
# chown cyrus /etc/pki/cyrus-imapd/
# vi /etc/imapd.conf

configdirectory: /var/lib/imap
partition-default: /var/spool/imap
admins: cyrus
sievedir: /var/lib/imap/sieve
sendmail: /usr/sbin/sendmail
hashimapspool: true
sasl_pwcheck_method: saslauthd
sasl_mech_list: PLAIN

tls_cert_file: /etc/pki/cyrus-imapd/
tls_key_file: /etc/pki/cyrus-imapd/

# vi /etc/cyrus.conf

imap          cmd=”imapd” listen=”imap” prefork=5
imaps         cmd=”imapd -s” listen=”imaps” prefork=1

Test STARTTLS by using imtest
# imtest -t “”

By default, Cyrus will cache SSL/TLS sessions for reuse for up to 24 hours. By adjusting the value of the tls_session_timeout option in imapd.conf, the session caching can be disabled (0) or the expiration period shortened.

Don’t forget to adjust the firewall to open port 993 for TCP (imaps:tcp in iptables) 



Problems with folders when using Squirelmail:

Q: Cyrus squirrelmail  ERROR : Could not complete request. Query: CREATE “Sent”
A: 1. Start of squirrelmail, select D, select cyrus.
2. Just use “Options – Folder Preferences” and set the “Sent” folder to a folder you created using for example cyradm. Squirrelmail “can” create folders only if you prefix them with “INBOX.”. So for example create (using squirrelmail) “INBOX.Sent”, go to the “Options – Folder Preferences” and set the Sentbox to “INBOX.Sent”.

Restoring email saved in Cyrus
Novell Cool Solutions: Question & Answer
Posted: 30 Apr 2004

Q: You never know what happened to me today. I deleted some email by mistake, and I need to restore from an available backup. We use Cyrus as the IMAP server and I have a backup of the directory /var/spool/imap/. Oh my God! What do I do now?
A: Cyrus saves email in this directory:


There is a file for each message. File names consist of successive numbers followed by a dot. To prevent existing messages with an identical “number” from being overwritten, it is advisable to first create an additional folder in which to install the backup.

Use the webmail interface to create a new folder under the relevant user (e.g., backup). To do this, select Configuration -> Folder -> New folder. The system creates a new folder with the path


(make sure not to create the folder manually. Otherwise, Cyrus will ignore it.)

Copy the messages to restore from your backup to the new folder. Restart your mailbox to make Cyrus acknowledge the new messages with

cyrus@mailserver:~> reconstruct -r user/<user_name>

or simply reconstruct without any option to restart all mailboxes.

Free BonusTip:

You can use the grep command to find messages based on certain criteria, such as the sender or subject. For example:
cyrus@mailserver:/tmp/<archive>/var/spool/imap/user> grep “From:” /smith/*

Roderick Derks

Liefhebber van fietsen, van het oplossen van IT puzzels, en van het delen van informatie om anderen te helpen.

All stories by:Roderick Derks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Your Name (required)

    Your Email (required)


    Your Message

      Your Name (required)

      Your Email (required)


      Your Message