如何安装和设置Dovecot邮件服务器与筛选和虚拟用户

如何安装和设置Dovecot邮件服务器与筛选和虚拟用户

本文档介绍如何从源代码安装Dovecot邮件服务器作为域的imap / pop3邮件服务器,以及如何设置筛选插件,以便客户端可以使用筛选邮件过滤语言进行邮件帐户管理。

获取来源

我们可以从http://dovecot.org下载Dovecot。 我总是喜欢稳定的版本,所以:

wget -c http://dovecot.org/releases/1.0/dovecot-1.0.13.tar.gz

我们还需要筛选插件源:

wget -c http://dovecot.org/releases/sieve/dovecot-sieve-1.0.2.tar.gz

2.安装Dovecot

此时我们可以继续安装dovecot邮件服务器

tar zxfv dovecot-1.0.13.tar.gz
cd dovecot
./configure
make
make install

现在我们需要安装筛子插件

tar zxfv dovecot-sieve-1.0.2.tar.gz
cd dovecot-sieve-1.0.2
./configure --with-dovecot=../dovecot-1.0.13
make
make install

3.配置

dovecot的基本配置文件是/usr/local/etc/dovecot.conf ,我们可以通过以下方式创建它:

cp -pi /usr/local/etc/dovecot-example.conf /usr/local/etc/dovecot.conf

dovecot的主要配置如下: http : //wiki.dovecot.org/MainConfig

以下配置是这些功能的基本配置文件:Imap协议,带Sieve插件的本地传递代理,来自文件的虚拟用户,并支持其他程序与dovecot邮件服务器进行身份验证。

# Dovecot configuration file
base_dir=/usr/local/var/run/
protocols = imap
listen = *:143
# We can use plain text passwords
disable_plaintext_auth = no
# Logging
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot.info.log
log_timestamp = "%b %d %H:%M:%S "
# SSL settings
# Without ssl
ssl_disable = yes
# Login processes
login_user = dovecot
login_greeting = Hi buddy, have an account ?
login_log_format = %$: %s
# Mailbox locations and namespaces
mail_extra_groups = mail
# Mailbox locations and namespaces
# Clients Inbox at /var/mail, Clients Folders at /var/mail/folders/username/
mail_location = mbox:/var/mail/folders/%u/:INBOX=/var/mail/%u
# Mail processes
mail_debug = yes
mail_log_prefix = "%Us(%u): "
verbose_proctitle = yes
first_valid_uid = 1000
last_valid_uid = 5000
max_mail_processes = 2048
# mbox-specific settings
mbox_read_locks = dotlock fcntl
mbox_write_locks = dotlock fcntl
# IMAP specific settings
protocol imap {
}
# LDA specific settings
protocol lda {
        postmaster_address = root@mydomain.org
        hostname = mydomain.org
# Sieve plugin for local delivery agent
        mail_plugins = cmusieve
        log_path = /var/log/dovecot-local-deliver.log
        auth_socket_path = /usr/local/var/run/dovecot-auth-master
}
# Authentication processes
auth_verbose = yes
auth_debug = yes
auth_debug_passwords = yes
auth default {
        mechanisms = plain
        passdb passwd-file {
        # Virtual Users from file
            args = /usr/local/etc/dovecot.passdb
        }
        userdb passwd-file {
        # Virtual Users from file
                args = /usr/local/etc/dovecot.passdb
        }
        user = root
# It's possible to export the authentication interface to other programs:
# For example getmail with MDA external
        socket listen {
          master {
            path = /usr/local/var/run/dovecot-auth-master
            mode = 0660
            user = dovecot
            group = mail
          }
        }
}

我们需要创建dovecot读取的配置文件来验证虚拟用户,

/usr/local/etc/dovecot.passdb
user1:{PLAIN}pass1:1001:1001:User 1 Name:/var/mail/folders/user1:: mail_plugins=cmusieve
user2:{PLAIN}pass2:1002:1002:User 2 Name:/var/mail/folders/user2:: mail_plugins=cmusieve
user3:{PLAIN}pass3:1003:1003:User 3 Name:/var/mail/folders/user3:: mail_plugins=cmusieve
user4:{PLAIN}pass4:1004:1004:User 4 Name:/var/mail/folders/user4:: mail_plugins=cmusieve

现在我们准备测试我们的imap邮件服务器。

4.开始和测试Dovecot

要启动dovecot邮件服务器,只需输入:

/usr/local/sbin/dovecot
ps -ef | grep dovecot

如果有任何问题只看日志文件。

tail -f /usr/local/dovecot*

验证运行dovecot的配置:

/usr/local/sbin/dovecot -n
# 1.0.13: /usr/local/etc/dovecot.conf
base_dir: /usr/local/var/run/
log_path: /var/log/dovecot.log
info_log_path: /var/log/dovecot.info.log
protocols: imap
listen: *:143
ssl_disable: yes
disable_plaintext_auth: no
login_dir: /usr/local/var/run//login
login_executable: /usr/local/libexec/dovecot/imap-login
login_greeting: Hi buddy, have an account ?
max_mail_processes: 2048
verbose_proctitle: yes
first_valid_uid: 1000
last_valid_uid: 5000
mail_extra_groups: mail
mail_location: mbox:/var/mail/folders/%u/:INBOX=/var/mail/%u
mail_debug: yes
mbox_read_locks: dotlock fcntl
auth default:
  verbose: yes
  debug: yes
  debug_passwords: yes
  passdb:
    driver: passwd-file
    args: /usr/local/etc/dovecot.passdb
  userdb:
    driver: passwd-file
    args: /usr/local/etc/dovecot.passdb
  socket:
    type: listen
    master:
      path: /usr/local/var/run/dovecot-auth-master
      mode: 432
      user: dovecot
      group: mail

如果一切到现在都运行正常,你应该通过telnet检查邮件服务器。 要做到这一点,请输入以下内容:

# telnet localhost 143
1 login username password

如果你使用上面的dovecot.conf,那么你应该这样测试:

# telnet mydomain.org 143
1 login user1 pass1

并检查INBOX:

# telnet mydomain.org 143
* OK Hi buddy, have an account ?
1 login user1 pass1
1 OK Logged in.
2 select inbox
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded \*)] Flags permitted.
* 8737 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1174418788] UIDs valid
* OK [UIDNEXT 112330] Predicted next UID
2 OK [READ-WRITE] Select completed.

如果你想检查它是否找到其他邮箱:

# telnet mydomain.org 143
* OK Hi buddy, have an account ?
1 login ebal test
1 OK Logged in.
2 SELECT INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded $Label3 $Label2 $Label4 $Label5 Junk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded $Label3 $Label2 $Label4 $Label5 Junk \*)] Flags permitted.
* 8737 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1174418788] UIDs valid
* OK [UIDNEXT 112330] Predicted next UID
2 OK [READ-WRITE] Select completed.
2 LIST "" *
* LIST (\NoInferiors \UnMarked) "/" "draft"
* LIST (\NoInferiors \UnMarked) "/" "Trash"
* LIST (\NoInferiors \UnMarked) "/" "INBOX"
2 OK List completed.

5.使用筛子

Sieve是一种邮件过滤语言,您可以在这里找到所有内容: http : //tools.ietf.org/html/rfc3028 。 Dovecot插件从我们的邮件位置读取.dovecot.sieve文件。 以上dovecot.conf将邮件位置设置为/ var / mail / folders / usename。 所以你需要创建文件:

touch /var/mail/folders/user1/.dovecot.sieve

根据rfc你可以写你的规则。 一个例子是:

require "fileinto";
if header :comparator "i;ascii-casemap" :contains "Subject" "**SPAM**"  {
        fileinto "Trash";
        stop;
}

此筛规则将标题主题包含“** SPAM **”的每封电子邮件传送到“垃圾桶”文件夹。

如果要验证您的筛选规则,这里是完美的项目: http : //libsieve-php.sourceforge.net/

如果您安装了apache,您可以设置网络邮件客户端,如Horde Groupware Webmail Edition或IlohaMail。

有用的链接

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏