Nastavení mail serveru

Z ZděchovNET
Skočit na navigaci Skočit na vyhledávání

Návod popisuje instalace poštovního serveru s virtuálními účty v MySQL databázi.

  • Budou použity následují komponenty:
    • postfix - SMTP server
    • dovecot - IMAP server
    • roundcubemail - web mail klient
    • postfixadmin - správa schránek


  • Nainstalujte potřebné balíčky
yum install postfix dovecot php-imap dovecot-mysql system-switch-mail roundcubemail

Stáhnout a nainstalovat Postfix Admin


  • Přidejte systémový účet pro virtuální schránky
# useradd vmail


  • Doplňte do souboru /etc/postfix/main.cf nastavení pro schránky:
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:505
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 505
virtual_transport = virtual
virtual_uid_maps = static:505

Obsažené číslo UID upravte dle systémového UID uživatele vmail.


  • Pokud váš server musí předávat poštu přes zadaný SMTP server, doplňte také řádek pro nastavení SMTP předávacího serveru
relayhost = smtp.zdechov.net


  • Dále vytvořte ve složce /etc/postfix soubory se zadaným obsahem a upravte přihlašovací pro váš MySQL server:

Soubor mysql_relay_domains_maps.cf

user = postfix
password = heslo
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '1'

Soubor mysql_virtual_alias_maps.cf

user = postfix
password = heslo
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

Soubor mysql_virtual_domains_maps.cf

user = postfix
password = heslo
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'

Soubor mysql_virtual_mailbox_limit_maps.cf

user = postfix
password = heslo
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'

Soubor mysql_virtual_mailbox_maps.cf

user = postfix
password = heslo
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'


  • Konfigurační soubor /etc/dovecot.conf nastavte např. takto:
dovecot.conf                                                                                      882/1668  UTF-8        52%
auth_debug_passwords = yes

# Log file to use for error messages, instead of sending them to syslog.
# /dev/stderr can be used to log into stderr.
log_path = /var/log/dovecot.log

# Log file to use for informational and debug messages.
# Default is the same as log_path.
info_log_path = /var/log/dovecot-info.log


# More verbose logging. Useful for figuring out why authentication isn't
# working.
auth_verbose = yes

# Even more verbose logging for debugging purposes. Shows for example SQL
# queries.
auth_debug = yes


mail_location = maildir:~/Maildir

#mail_location = maildir:/home/vmail/%d/%u
first_valid_uid = 505
last_valid_uid = 505
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@domena.cz
  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 {
}


  • Pak nastavení Dovecotu pro přípojení k MySQL serveru je potřeba vytvořit v souboru /etc/dovecot/sql.conf takto:
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=heslo
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 505 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('/home/vmail/', maildir) as userdb_home, concat('maildir:/home/vm
ail/', maildir) as userdb_mail, 505 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'


  • Nastavit automatické spouštění potřebných služeb
chkconfig dovecot on
chkconfig postfix on

Vnější odkazy