Linux

Debian Linux 7.0 Sendmail/Dovecot Mail Directory Maildir Setup

By accident I restarted the dovecot service, and then all the previously received mails in the list disappeared. Then came an endless search, and I finally trac

By accident I restarted the dovecot service, and then all the previously received mails in the list disappeared. Then came an endless search, and I finally traced it to the mail storage directory setting. Regarding mail storage formats, the two popular ones are mbox and maildir, and articles comparing them are everywhere online. But for me, the most important point is that mbox stores all mails in a single file, whereas maildir stores each mail in a separate file. As a result, for accidental file deletions causing lost mail, the probability of loss is much higher with mbox than with maildir. Moreover, when a single file grows to a certain size, the read/write overhead is also something to consider. The following are the steps to change the storage format of dovecot and sendmail from mbox to maildir. Assume the user is "user" and the mail directory is the "mail" folder under the user's home directory. 1. Create the relevant folders.

Bash

# su - user
$ mkdir -p ~/mail/new
$ mkdir ~/mail/cur
$ mkdir ~/mail/tmp
  1. Edit the configuration file >/etc/dovecot/conf.d/10-mail.conf Add the following line, or modify the existing mail_location line.
mail_location = maildir:~/mail

Comment out the line mail_location = mbox in >/etc/mail/sendmail and add the following three lines

Existing settings: dnl # FEATURE(local_procmail, `', `procmail -t -Y -a $h -d$u')dnl
Modified Settings: FEATURE(local_procmail)dnl
MAILER(procmail)dnl

If restarting the sendmail service throws the error "*** ERROR: FEATURE() should be before MAILER()", refer to "sendmail error log collection" and append the following three lines to the end of the file.

MAILER_DEFINITIONS
MAILER(`local')dnl
MAILER(`smtp')dnl

/etc/procmailrc (create the file if it does not exist)

PATH=/usr/local/bin:/usr/bin:/bin
MAILDIR=$HOME/mail
DEFAULT=$MAILDIR/new
LOGFILE=$MAILDIR/log
  1. Restart the service and send a test email

/etc/init.d/sendmail restart && /etc/init.d/dovecot restart

After completing the above steps, my testing showed that sendmail and dovecot must use the same maildir directory for normal sending/receiving (and both must be either mbox or maildir). Once the email is configured in the client, sending and receiving are both fine—except the system says the Sent folder cannot be found. And in /home/user/mail, there's no trace of Inbox, Sent, etc. After using the mb2md tool to import the original-format mail, the problem was resolved. I believe that creating ".Inbox" and ".Sent" under /home/user/mail would also solve the problem.

  1. Importing the original mbox-format mail Install the tool

Bash

# apt-get update && apt-get install mb2md

Bash

# su - user
$ echo $MAIL

If the MAIL variable holds the original mbox path used by dovecot for the inbox, simply run the command below. Otherwise, run export MAIL="/var/mail/user" to set the MAIL variable's value (modify the path as needed) first, then run the following command.

Bash

$ mb2md -m

Or, specify the source and destination directories in the tool's parameters, and add the "-R" parameter to automatically create the relevant directories (such as ".Sent", ".Inbox", etc.)

Bash

$ mb2md -s source_dir -d target_dir (here /home/user/mail) -R

Restart the dovecot and sendmail services, then check the email client for the previous emails; if they appear, the import was successful.

Note: After the above steps are done, under "Maildir", the Sent folder and similar folders are named ".Send". If you want to change them to "Sent", you need to add ":LAYOUT=fs" after the line "mail_location = maildir:~/mail" in the file "/etc/dovecot/conf.d/10-mail.conf". For details, see "http://wiki2.dovecot.org/MailLocation/Maildir".

N
norvyn

独立 iOS 开发者,写字的人。在一座有海的城市,慢慢地做一些小而确定的东西。An independent iOS developer and writer — slowly making small, certain things in a city by the sea.

评论Comments

加载中…Loading…

留下评论Leave a comment