我正在家里设置自己的 Ubuntu 邮件服务器(postfix-mysql-dovecot-roundcube),并使用 MX 注册域名(在我的示例中为“domain.com”)。
我的 main.cf:
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname Welcome
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file = /etc/ssl/certs/server.crt
smtpd_tls_key_file = /etc/ssl/private/server.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
relayhost =
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = domain.com
alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
myorigin = /etc/mailname
mydestination = localhost
mynetworks = 127.0.0.0/8, 192.168.2.0/24, 192.168.1.0/24
mailbox_size_limit = 5368709120
recipient_delimiter = +
inet_protocols = ipv4
inet_interfaces = all
queue_directory = /mail/postfix
home_mailbox = Maildir/
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes
smtpd_sender_restrictions = reject_unknown_sender_domain
mailbox_command = /usr/lib/dovecot/dovecot-lda -f "$SENDER" -a "$RECIPIENT" -d "$USER"
smtp_use_tls = yes
smtpd_tls_received_header = yes
smtpd_tls_mandatory_protocols = SSLv3, TLSv1
smtpd_tls_mandatory_ciphers = medium
smtpd_tls_auth_only = yes
tls_random_source = dev:/dev/urandom
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
virtual_uid_maps = static:150
virtual_gid_maps = static:8
virtual_mailbox_base = /mail/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_mailbox_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
relay_domains = mysql:/etc/postfix/mysql_relay_domains.cf
relay_recipient_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
milter_default_action = accept
master.cf:
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
smtps inet n - - - - smtpd
pickup unix n - y 60 1 pickup
cleanup unix n - y - 0 cleanup
qmgr unix n - n 300 1 qmgr
#qmgr unix n - n 300 1 oqmgr
tlsmgr unix - - y 1000? 1 tlsmgr
rewrite unix - - y - - trivial-rewrite
bounce unix - - y - 0 bounce
defer unix - - y - 0 bounce
trace unix - - y - 0 bounce
verify unix - - y - 1 verify
flush unix n - y 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - y - - smtp
relay unix - - y - - smtp
showq unix n - y - - showq
error unix - - y - - error
retry unix - - y - - error
discard unix - - y - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - y - - lmtp
anvil unix - - y - 1 anvil
scache unix - - y - 1 scache
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
dovecot unix - n n - - pipe
flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/dovecot-lda -d ${recipient}
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail unix - n n - - pipe
flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe
flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe
flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe
flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
${nexthop} ${user}
我按照一些在线教程定义了 postfix-mysql 和 dovecot 的所有其他文件。我可以接收外部电子邮件,但它们被卡在 postix 队列中。当我尝试检索它们时,我得到了以下日志行:
May 16 11:03:36 mail postfix/qmgr[4236]: 719CE44008A: from=<[email protected]>, size=2220, nrcpt=1 (queue active)
May 16 11:03:36 mail postfix/trivial-rewrite[22152]: warning: do not list domain domain.com in BOTH virtual_mailbox_domains and relay_domains
May 16 11:03:36 mail postfix/lmtp[22153]: 719CE44008A: to=<[email protected]>, relay=none, delay=50625, delays=50625/0.14/0/0, dsn=4.4.1, status=deferred (connect to domain.com[private/dovecot-lmtp]: No such file or directory)
任何想法 ?
这是 dovecot 的主配置文件(dovecot.conf):
# 2.2.22 (fe789d2): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.4.13 (7b14904)
# OS: Linux 4.4.0-22-generic x86_64 Ubuntu 16.04 LTS
auth_mechanisms = plain login
disable_plaintext_auth = no
first_valid_gid = 8 # mail group gid
first_valid_uid = 150 # vmail user uid
listen = *
mail_debug = yes
mail_gid = mail
mail_location = maildir:~/Maildir
mail_privileged_group = mail
mail_uid = vmail
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext
namespace inbox {
inbox = yes
location =
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox Trash {
special_use = \Trash
}
prefix =
}
passdb {
args = /etc/dovecot/dovecot-sql.conf.ext
driver = sql
}
plugin {
sieve = ~/.dovecot.sieve
sieve_dir = ~/sieve
}
postmaster_address = [email protected]
protocols = imap lmtp
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
unix_listener /var/spool/postfix/private/dovecot-auth {
group = postfix
mode = 0660
user = postfix
}
unix_listener auth-userdb {
group = mail
mode = 0660
user = vmail
}
}
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
group = postfix
mode = 0600
user = postfix
}
}
ssl_cert = </etc/dovecot/dovecot.pem
ssl_cipher_list = ALL:!LOW:!SSLv2:ALL:!aNULL:!ADH:!eNULL:!EXP:RC4+RSA:+HIGH:+MEDIUM
ssl_key = </etc/dovecot/private/dovecot.pem
userdb {
args = /etc/dovecot/dovecot-sql.conf.ext
driver = sql
}
protocol lmtp {
mail_plugins = quota sieve
postmaster_address = [email protected]
}
protocol lda {
deliver_log_format = msgid=%m: %$
mail_plugins = sieve
postmaster_address = postmaster
quota_full_tempfail = yes
rejection_reason = Your message to <%t> was automatically rejected:%n%r
}
protocol imap {
imap_client_workarounds = delay-newmail
mail_max_userip_connections = 10
}
protocol pop3 {
mail_max_userip_connections = 10
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
}
dovecot-sql.conf.ext 配置文件:
# This file is commonly accessed via passdb {} or userdb {} section in
# conf.d/auth-sql.conf.ext
# This file is opened as root, so it should be owned by root and mode 0600.
#
# http://wiki2.dovecot.org/AuthDatabase/SQL
#
# Database driver: mysql, pgsql, sqlite
driver = mysql
connect = host=db dbname=mail_db user=usermail password=password
default_pass_scheme = MD5-CRYPT
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT '/mail/vmail/%d/%n' as home, 150 AS uid, 8 AS gid FROM mailbox WHERE username = '%u'
# If you wish to avoid two SQL lookups (passdb + userdb), you can use
# userdb prefetch instead of userdb sql in dovecot.conf. In that case you'll
# also have to return userdb fields in password_query prefixed with "userdb_"
# string. For example:
#password_query = \
# SELECT userid AS user, password, \
# home AS userdb_home, uid AS userdb_uid, gid AS userdb_gid \
# FROM users WHERE userid = '%u'
# Query to get a list of all usernames.
#iterate_query = SELECT username AS user FROM mailbox
Dovecot 服务器状态:
dovecot.service - Dovecot IMAP/POP3 email server
Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
Active: active (running) since lun. 2016-05-16 17:52:28 CEST; 1min 42s ago
Docs: man:dovecot(1)
http://wiki2.dovecot.org/
Process: 4624 ExecStart=/usr/sbin/dovecot (code=exited, status=0/SUCCESS)
Main PID: 4627 (dovecot)
Tasks: 4 (limit: 512)
CGroup: /system.slice/dovecot.service
├─4627 /usr/sbin/dovecot
├─4629 dovecot/anvil
├─4630 dovecot/log
└─4632 dovecot/config
mai 16 17:52:28 mail.lidric.net systemd[1]: Starting Dovecot IMAP/POP3 email server...
mai 16 17:52:28 mail.lidric.net dovecot[4624]: Error: systemd listens on port 143, but it's not configured in Dovecot. Closing.
mai 16 17:52:28 mail.lidric.net dovecot[4624]: master: Error: systemd listens on port 143, but it's not configured in Dovecot. Closing.
mai 16 17:52:28 mail.lidric.net dovecot[4624]: Error: systemd listens on port 993, but it's not configured in Dovecot. Closing.
mai 16 17:52:28 mail.lidric.net dovecot[4624]: master: Error: systemd listens on port 993, but it's not configured in Dovecot. Closing.
mai 16 17:52:28 mail.lidric.net systemd[1]: dovecot.service: PID file /var/run/dovecot/master.pid not readable (yet?) after start: No such file or directory
mai 16 17:52:28 mail.lidric.net dovecot[4627]: master: Dovecot v2.2.22 (fe789d2) starting up for lmtp, imap (core dumps disabled)
mai 16 17:52:28 mail.lidric.net systemd[1]: Started Dovecot IMAP/POP3 email server.