首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > 服务器相关 > New mail server (debian + exim4 + dovecot IMAP)
【标  题】:New mail server (debian + exim4 + dovecot IMAP)
【关键字】:New,mail,server,debian,exim4,dovecot,IMAP
【来  源】:http://www.cublog.cn/u/6418/showart.php?id=76763

New mail server (debian + exim4 + dovecot IMAP)


Choice of mailbox format

The key decision you need to make before choosing the IMAP server is the mail folder format. Each IMAP server has a preferred mail box format, so choosing the right format first time, could save you a lot of time down the track. You have the choice of:

  • mbox — the traditional UNIX format. One file contains all mail in the folder
  • mbx — an updated version of mbox that make some common operations faster
  • maildir — each message is stored in a separate file within a directory

To me the idea of storing all mail in a single text file sounds a horrible. When you delete a single message from a huge mail folder, the whole file could have to be rewritten. Care must also be taken so that 2 processes don’t try to update the mail folder at once, otherwise corruption could occur. The mbox/mbx vs. maildir issue seems to be fairly contentious, but to me maildir seemed the more natural way to go. It also allows us to write simple scripts to move mail between folder (… something we do when setting up the spam filtering below).

Choice of IMAP server

Now that we’ve chosen maildir as the mail box format, we need to choose an IMAP server. The main choices are:

  • Courier — very popular but complex
  • Dovecot — simple and uses indexing to make folder and message access fast

Simple and fast sounded good to me … so Dovecot got the nod.

The MTA — Exim4

The server started it’s life as a Debian 3 “Woody” which used Exim3 as its MTA. Exim3 was doing a fine job, but given that Exim 4 is the default for the upcoming Debian release and Exim3 was no longer developed I chose to upgrade.

apt-get install exim4

… answer a couple of questions … and it’s working perfectly! Lovely.

The only thing we need to do to tell Exim to deliver to a maildir instead of the mbox default. In Debian it’s just a matter of setting the LOCAL_DELIVERY=maildir_home in the exim config file. The result of this is that an exim router for local mail is configured to deliver mail to the following transport:

maildir_home:
debug_print = \"T: maildir_home for $local_part@$domain\"
driver = appendfile
directory = $home/Maildir
delivery_date_add
envelope_to_add
return_path_add
maildir_format
mode = 0600
mode_fail_narrower = false

Make sure you restart exim …

~$ /etc/init.d/exim4 restart
Restarting MTA: exim4.

To test that things are working correctly try something like this:

~$ sendmail localuser
hello
.

If all went well, a maildir should be created for the user you sent the mail to in . The new/ subdirectory should contain a file containing the message you just sent.

If that didn’t work, you might have to look through some logs to see what went wrong. On Debian, look for:

/var/log/mail.info
/var/log/mail.err
/var/log/exim4/exim4.log

OK, now for the IMAP setup…

Installing Dovecot IMAP

Some more Debian magic …

apt-get install dovecot

… connect to the server with Mozilla Thunderbird using IMAP. Hey, presto … it works!! I can see the test email in the inbox.

OK, so local mail delivery is now working. But that’s not very exciting. All our mail gets delivered to POP accounts on the hosting service. To deliver the mail locally I use fetchmail which periodically polls one or more POP inboxes and delivers the mail to local users via the local MTA. (I actually have more than one POP account … but fetchmail can handle that with ease.

Setting up fetchmail

Once fetchmail is installed it’s a simple of matter of telling it where to fetch the mail from. Create a file in your home directory called .fetchmailrc, and for each POP account you want to collect mail from add a line:

poll mail.myisp.com protocol pop3 user \"username\" pass \"password\"
is \"localuser\" here keep

The keep option tells fetchmail to keep the mails on the POP server. This is recommended until you’re sure it’s all working. Otherwise an incorrect mail server setup my cause you to lose mail.

To test that it’s working ok type:

~$ fetchmail
fetchmail: No mail for username at mail.myisp.com

It will output details of the connection to your mail server(s) and whether it retrieved any mail. It’s probably a good idea to send some test mail to your account and then re-run fetchmail. If all goes well the mail will end up in the ~/Maildir/new directory. (NOTE: Try to send mail from a different account … because if something goes wrong you won’t be able to easily see the delivery failure message.)

If you call fetchmail with the -F option it will delete any messages that it’s already downloaded. So I’ve set up a crontab to call fetchmail every 5 mins and leave the mail on the server. Then once a day I call fetchmail -F to clear mails from the POP account. This way if something goes wrong with the mail server, then the mail will be stored safely on the POP server for 24 hours. So nothing will get lost.

Phew … that’s it for now

In the next installment I’ll discuss setting up spam blocking with spamprobe and SquirrelMail for web-based mail access.

6 Responses to “New mail server (debian + exim4 + dovecot IMAP)”

  1. Gaea Says:

    Thanks very much for the tips! I’ve been trying to get pop –> fetchmail –> exim4 –> spamassassin –> etcetera –> squirrelmail for the past day or so, found this entry googling, and a few of your tips were really handy. I now have external and internal mail in ~/Maildir/new, so that’s something, eh? I set up IlohaMail with an sql backend the other day, but the no folders thing got to me and I decided it was time to really make myself miserable apt-getting and –purge-ing, going back and forth between courier and dovecot and uw and so forth. :>

    Thanks again.

  2. skippy Says:

    This follow up about speed suggests that other MUAs will not enjoy the speed benefits of Dovecot’s indexing, due (I assume) to client-side caching. I, and most of my users, use Mozilla Thunderbird for IMAP access. I’m curious what MUA you use, and what your perceived performance has been like?

  3. Matt Doran Says:

    I do use Mozilla Thunderbird, and it performs excellently. I switched to Thinderbird about 2 months ago and won’t go back.

    My largest mail folder has about 3200 messages and sorting it is almost instantaneous. Searching is messages is also very fast. If I search message the message bodies in this folder it takes only about 1-2 seconds.

  4. geos Says:

    for the life of me i cant find where this goes

    “The only thing we need to do to tell Exim to deliver to a maildir instead of the mbox default. In Debian it’s just a matter of setting the LOCAL_DELIVERY=maildir_home in the exim config file. The result of this is that an exim router for local mail is configured to deliver mail to the following transport”

    I recomend when you say change “this” you mention what to change

  5. Matt Doran Says:

    On Debian this is in one of the files in /etc/exim4/. grep the files in there to find it. I’m using Debians split up exim config files, so for me it’s in /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs.

    The section of the file you’re looking for looks like this …

    # The default delivery method. See CONFDIR/conf.d/transports/ for other
    # possibilities
    LOCAL_DELIVERY=maildir_home

  6. Pieter Says:

    I had to jump through the following hoops.

    Edit /etc/exim/update-exim4.conf.conf
    and add
    > dc_localdelivery=maildir_home
    run dpkg-reconfigure exim4-config

    I think it is because dpkg is managing my config.

sarge+postfix+mysql+webmail+web admin安装配置指南:【上一篇】
Setting up an IMAP server with dovecot:【下一篇】
【相关文章】
  • sarge+postfix+mysql+webmail+web admin安装配置指南
  • 我想翻译qmail的参考手册
  • 第一次安装qmail
  • qmail+vpopmail安装笔记
  • RedHat Enterprise Linux Server 4.2 + OpenLDAP + ..
  • 简明的IMAP用法,详见RFC2060
  • print from and subject of messages in mailbox
  • qmail+vpopmail+squirrelmail 安装经验谈
  • Maildrop规则样例(支持解码)
  • qmail完全解决方案
  • 【随机文章】
  • 进行有效编辑的七种习惯
  • 基于Java的高性能TP Monitor的设想
  • Winform DataGrid设计三步曲之一-----DataGrid如何动态实现多种风格(TableStyle)之间的转换
  • SOA不是Web服务
  • 一组不寻常的中国造机器人图片
  • 写给入门新手的-我的网络黑客经历
  • Windows XP问题的精彩问答
  • Linux简明系统维护手册(三)
  • 使用SSH建立基于Linux/Unix的VPN网络
  • SM240第五章读书笔记
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.