Postfix - Virtual Domains
Z wiki linux-user
Linia 139: | Linia 139: | ||
mysql> flush privileges; | mysql> flush privileges; | ||
mysql> exit | mysql> exit | ||
+ | |||
+ | == Dovecot == | ||
+ | |||
+ | Konfiguracja pakietu '''Dovecot''' | ||
+ | Tworzymy folder w którym będziemy przechowywać foldery użytkowników poczty, oczywiście może to być dowolna lokalizacja | ||
+ | |||
+ | mkdir -p /var/vmail | ||
+ | chmod 770 /var/vmail | ||
+ | |||
+ | Tworzymy użytkownika '''vmail''' i nadajemy odpowiednie uprawnienia do katalogu ''/var/vmail'' | ||
+ | |||
+ | useradd -r -u 101 -g mail -d /var/vmail -s /sbin/nologin -c "Virtual mailbox" vmail | ||
+ | chown vmail.mail /var/vmail | ||
+ | |||
+ | |||
+ | Edytujemy plik ''/etc/dovecot.conf'' tak aby wyglądał następująco | ||
+ | |||
+ | ssl_cert_file = /etc/pki/dovecot/certs/myserver.example.com.crt | ||
+ | ssl_key_file = /etc/pki/dovecot/private/myserver.example.com.key | ||
+ | ssl_ca_file = /etc/pki/dovecot/certs/ca-bundle.crt | ||
+ | mail_location = maildir:/var/vmail/%d/%u | ||
+ | first_valid_uid = 101 | ||
+ | last_valid_uid = 101 | ||
+ | maildir_copy_with_hardlinks = yes | ||
+ | protocol imap { | ||
+ | mail_plugins = quota imap_quota | ||
+ | imap_client_workarounds = outlook-idle delay-newmail | ||
+ | } | ||
+ | protocol pop3 { | ||
+ | mail_plugins = quota | ||
+ | pop3_client_workarounds = outlook-no-nuls oe-ns-eoh | ||
+ | } | ||
+ | protocol lda { | ||
+ | postmaster_address = | ||
+ | postmaster@example.com | ||
+ | mail_plugins = quota | ||
+ | log_path = /var/log/dovecot-deliver.log | ||
+ | info_log_path = /var/log/dovecot-deliver.log | ||
+ | } | ||
+ | auth default { | ||
+ | # Having "login" also as a mechanism make sure outlook can use the auth smtpd as well | ||
+ | # http://wiki.dovecot.org/Authentication/Mechanisms | ||
+ | mechanisms = plain login | ||
+ | passdb sql { | ||
+ | args = /etc/dovecot/sql.conf | ||
+ | } | ||
+ | userdb sql { | ||
+ | args = /etc/dovecot/sql.conf | ||
+ | } | ||
+ | userdb prefetch { | ||
+ | } | ||
+ | user = nobody | ||
+ | socket listen { | ||
+ | master { | ||
+ | path = /var/run/dovecot/auth-master | ||
+ | mode = 0660 | ||
+ | user = vmail | ||
+ | group = mail | ||
+ | } | ||
+ | client { | ||
+ | path = /var/spool/postfix/private/auth | ||
+ | mode = 0660 | ||
+ | user = postfix | ||
+ | group = mail | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | dict { | ||
+ | } | ||
+ | plugin { | ||
+ | quota = maildir:storage=10240:messages=1000 | ||
+ | acl = vfile:/etc/dovecot/acls | ||
+ | trash = /etc/dovecot/trash.conf | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Oczywiście w niektórych miejscach powinniśmy dostosować go do własnych potrzeb. | ||
+ | |||
+ | |||
+ | Tworzymy certyfikaty dla dovecot | ||
+ | Jak to zrobić opisane jest tutaj | ||
+ | |||
+ | Przenosząc certyfikaty w odpowiednie miejsca | ||
+ | |||
+ | ssl_cert_file = /etc/pki/dovecot/certs/myserver.example.com.crt | ||
+ | ssl_key_file = /etc/pki/dovecot/private/myserver.example.com.key | ||
+ | ssl_ca_file = /etc/pki/dovecot/certs/ca-bundle.crt | ||
+ | |||
+ | |||
+ | Tworzymy plik /etc/dovecot/sql.conf i edytujemy go, aby wyglądał w następujący sposób: | ||
+ | |||
+ | driver = mysql | ||
+ | default_pass_scheme = md5 | ||
+ | connect = host=localhost dbname=postfix user=dovecot password=dovecot | ||
+ | user_query = SELECT concat('/var/vmail/', maildir) as home, concat('maildir:/var/vmail/', maildir) as mail, 101 AS uid, 12 AS gid, / | ||
+ | concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' | ||
+ | # fast but now so nice:-) | ||
+ | #user_query = SELECT '/var/vmail/%d/%n' as home, 'maildir:/var/vmail/%d/%n' as mail, 101 AS uid, 12 AS gid, / | ||
+ | concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' | ||
+ | # Just in case you are using postfix the delimiter char "+", the above query will probably fail for the username / | ||
+ | '%n' or '%u' and result in a "5.5.1 user unknown" error | ||
+ | #in this case, you will probalby want to use a separate user and domain part, whilst searching only / | ||
+ | for the destination user part (user_query only): | ||
+ | # SELECT ... WHERE username = substring_index('%n','+',1) AND userrealm = '%d' | ||
+ | password_query = SELECT username as user, password, concat('/var/vmail/', maildir) as userdb_home, / | ||
+ | concat('maildir:/var/vmail/', maildir) as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox / | ||
+ | WHERE username = '%u' AND active = '1' | ||
+ | # fast but now so nice:-) | ||
+ | #password_query = SELECT username as user, password, '/var/vmail/%d/%n' as userdb_home, / | ||
+ | 'maildir:/var/vmail/%d/%n' as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox / | ||
+ | WHERE username = '%u' AND active = '1' | ||
+ | |||
+ | UWAGA !! linie ze znakiem / są przełamane jeśli będziesz robił kopiuj wklej pamiętaj o połączeniu tych lini | ||
+ | |||
+ | Jeśli zachodzi potrzeba to dostrajamy go do swoich potrzeb. | ||
+ | |||
+ | Kolejny plik który tworzymy to /etc/dovecot/trash.conf i dodajemy do niego | ||
+ | |||
+ | 1 Spam | ||
+ | 2 Trash |