
root@mailsrv:~# apt install postfix sasl2-bin dovecot-core dovecot-pop3d dovecot-imapd
Choose:
Internet site / No configuration
——————————————-
root@mailsrv:~# vim /etc/postfix/main.cf
// for ipv4 only please set:
mynetworks = 127.0.0.0/8
Read More//add:
# SMTP-Auth settings
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject
// save & quit
root@mailsrv:~# newaliases
root@mailsrv:~# systemctl restart postfix
root@mailsrv:~# vim /etc/dovecot/dovecot.conf
Uncomment
listen = *, ::
// save & quit
root@mailsrv:~# vim /etc/dovecot/conf.d/10-auth.conf
Uncomment „#disable_plaintext_auth = yes” and set to ‚no’
disable_plaintext_auth = no
Find option „auth_mechanisms” and add ‚login’
auth_mechanisms = plain login
Find ‚mail_location’ option and set to maildir – it is more efficient than default mbox.
mail_location = maildir:~/Maildir
this option stores mails in home directory, you can also configure it to store in /var/mail/username location:
mail_location = maildir:/var/mail/%u
// save & quit
root@mailsrv:~# vim /etc/dovecot/conf.d/10-master.conf
Uncomment:
unix_listener /var/spool/postfix/private/auth {
mode = 0666
}
and add two lines:
user = postfix
group = postfix
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
// save & quit
root@mailsrv:~# systemctl restart dovecot
#————————————————————-
Virtual users in Dovecot DB:
Create an administrative account – user ‚vmail’ to manage virtual mailboxes:
root@mailsrv:~# adduser –uid 20000 –disabled-password –disabled-login vmail
root@mailsrv:~# vim /etc/postfix/main.cf
Comment out line:
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
Add below lines:
virtual_mailbox_domains = botulinski.com, virtual.host
virtual_mailbox_base = /home/vmail
virtual_mailbox_maps = hash:/etc/postfix/virtual-mailbox
virtual_uid_maps = static:20000
virtual_gid_maps = static:20000
// save & quit
root@mailsrv:~# vim /etc/dovecot/conf.d/10-auth.conf
Add ‚cram-md5’ option to ‚auth_mechanisms’:
auth_mechanisms = cram-md5 plain login
Add comment to line:
#!include auth-system.conf.ext
and uncomment these two options:
!include auth-passwdfile.conf.ext
!include auth-static.conf.ext
// save & quit
root@mailsrv:~# vim /etc/dovecot/conf.d/auth-passwdfile.conf.ext
Change ‚CRYPT’ to ‚CRAM-MD5’ in passdb section:
passdb {
driver = passwd-file
args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/users
}
Comment out whole userdb section:
#userdb {
# driver = passwd-file
# args = username_format=%u /etc/dovecot/users
# Default fields that can be overridden by passwd-file
#default_fields = quota_rule=*:storage=1G
# Override fields from passwd-file
#override_fields = home=/home/virtual/%u
#}
// save & quit
root@mailsrv:~# vim /etc/dovecot/conf.d/auth-static.conf.ext
Uncomment userdb section, and set ‚home’ as below:
userdb {
driver = static
args = uid=vmail gid=vmail home=/home/vmail/%d/%n
}
// save & quit
root@mailsrv:~# vim /etc/dovecot/conf.d/10-mail.conf
Change:
mail_location = maildir:/home/vmail/%d/%n/Maildir
// save & quit
root@mailsrv:~# systemctl restart postfix
root@mailsrv:~# systemctl restart dovecot
#————————————————————-
Add virtual users in Dovecot DB:
root@mailsrv:~# vim /etc/postfix/virtual-mailbox
# create new
# [user account] [mailbox]
paul@mailsrv.com mailsrv.com/paul/Maildir/
root@mailsrv:~# postmap /etc/postfix/virtual-mailbox
Generate encrypted password:
root@mailsrv:~# doveadm pw -s CRAM-MD5
Enter new password:
Retype new password:
{CRAM-MD5}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//Copy string with encrypted password
root@mailsrv:~# vim /etc/dovecot/users
#Add lines to file (paste encrypted password):
paul@mailsrv.com:{CRAM-MD5}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx