[1] 編譯
更新 postfix-2.3.3
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -DUSE_SASL_AUTH -DUSE_TLS -DDEF_SERVER_SASL_TYPE="dovecot" -I/usr/include/mysql' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lssl -lcrypto -lz -lm'
make upgrade
更新 dovecot-1.0.rc15
./configure –with-pgsql –with-sql –with-pam –with-shadow –with-passwd-file –with-passwd –with-mysql
make && make install
[2] 建立 MySQL
CREATE TABLE `domains` (
`domain` varchar(255) collate utf8_bin NOT NULL,
`path` varchar(255) collate utf8_bin NOT NULL,
UNIQUE KEY `domain` (`domain`)
);CREATE TABLE `emails` (
`id` int(10) NOT NULL auto_increment,
`account` varchar(255) collate utf8_bin NOT NULL,
`domain` varchar(255) collate utf8_bin NOT NULL,
`password` varchar(32) collate utf8_bin NOT NULL,
`quota` int(10) NOT NULL default '0',
`alias` int(10) NOT NULL default '0',
UNIQUE KEY `id` (`id`)
);
[3] Postfix設定
vi /etc/postfix/main.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql/domains.cfg
virtual_mailbox_base = /var/mail
virtual_mailbox_maps = mysql:/etc/postfix/mysql/mboxes.cfg
virtual_alias_maps = mysql:/etc/postfix/mysql/aliases.cfg
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_transport = virtualsmtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
mkdir /etc/postfix/mysql
vi /etc/postfix/mysql/domains.cfg
user = mysqluser
password = mysqlpassword
dbname = ccc
query = SELECT domain FROM domains WHERE domain = '%s'
hosts = localhost
vi /etc/postfix/mysql/mboxes.cfg
user = mysqluser
password = mysqlpassword
dbname = ccc query = SELECT concat(domain, '/', account, '/',account) FROM emails WHERE account = '%u' AND domain = '%d' AND alias = 0
hosts = localhost
vi /etc/postfix/mysql/aliases.cfg
user = mysqluser
password = mysqlpassword
dbname = ccc
query = SELECT concat(e2.account, '@', e2.domain) FROM emails as e1, emails as e2
WHERE e1.account = '%u' AND e1.domain = '%d' AND e1.alias > 0 AND e1.alias = e2.id
hosts = localhost
[4] Dovecot設定,Tarball安裝
cd /usr/local/etc
cp dovecot-sample.conf dovecot.conf
vi dovecot.conf
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
ssl_disable = yes
protocol pop3 {
pop3_uidl_format = %v.%u
}
auth_verbose = yes
auth_debug = yes
default_mail_env = mbox:/var/mail/%d/%n:INBOX=/var/mail/%d/%n/%n
auth default {
mechanisms = plain login cram-md5 digest-md5passdb sql {
args = /etc/dovecot-mysql.conf
}userdb static {
args = uid=5000 gid=5000 home=/var/mail/%d/%n
}socket listen {
client {
user = postfix
group = postfix
path = /var/spool/postfix/private/auth
mode = 0660
}
}
}
vi /usr/local/etc/dovecot-mysql.conf
driver = mysql
connect = host=/var/lib/mysql/mysql.sock user=mysqluser password=mysqlpassword dbname=ccc
default_pass_scheme = PLAIN
password_query = SELECT password FROM emails WHERE account = '%n' AND domain = '%d' AND alias = 0
建立 mail owner
groupadd -g 5000 mailowner
useradd -g 5000 -u 5000 -d /var/mail -p somesecretpassword -s /bin/false mailowner
chown -R mailowner:mailowner /var/mail
ref: http://postfix.pentachron.net
測試 Dovecot
[root@ssorc ~]# telnet localhost 143
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
* OK Dovecot ready.
1 login cross2 123456
1 OK Logged in.
2 select inbox
* FLAGS (Answered Flagged Deleted Seen Draft)
* OK [PERMANENTFLAGS (Answered Flagged Deleted Seen Draft *)] Flags permitted.
* 1 EXISTS
* 0 RECENT
* OK [UNSEEN 1] First unseen.
* OK [UIDVALIDITY 1189174128] UIDs valid
* OK [UIDNEXT 2] Predicted next UID
2 OK [READ-WRITE] Select completed.
3 list "" *
* LIST (HasNoChildren) "." "INBOX"
3 OK List completed.
至於什麼是 Sieve: 就是系統面的郵件規則
ref: http://www.howtoforge.com/dovecot_mail_server_sieve_virtual_users
留言