Tag Archives: postfix

postfix dovecot virtual mailbox

Centos 7 + Postfix + Dovecot (without database)

vi /etc/postfix/main.cf
home_mailbox = Maildir/
myhostname = localhost

groupadd -g 5000 vmail
useradd -m -u 5000 -g 5000 -s /bin/bash vmail

vi /etc/postfix/main.cf
virtual_mailbox_domains = /etc/postfix/vhosts
virtual_mailbox_base = /home/vmail
virtual_mailbox_maps = hash:/etc/postfix/vmaps
virtual_minimum_uid = 1000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

vi /etc/postfix/vhosts
domain1.com
domain2.com

vi /etc/postfix/vmaps
[email protected] domain1.com/info/
[email protected] domain1.com/info/
[email protected] domain1.com/sales/
[email protected] domain2.com/info/
[email protected] domain2.com/sales/

postmap /etc/postfix/vmaps
service postfix restart

vi /etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu/GNU)
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

myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $myhostname
mynetworks = 127.0.0.0/8, 10.0.0.0/24
mailbox_size_limit = 0
home_mailbox = Maildir/
virtual_mailbox_domains = /etc/postfix/vhosts
virtual_mailbox_base = /home/vmail
virtual_mailbox_maps = hash:/etc/postfix/vmaps
virtual_minimum_uid = 1000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
recipient_delimiter = +
inet_interfaces = all

mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.orig
vi /etc/dovecot/dovecot.conf
# 2.2.10: /etc/dovecot/dovecot.conf
# OS: Linux 3.10.0-327.36.3.el7.x86_64 x86_64 CentOS Linux release 7.2.1511 (Core) ext4
auth_mechanisms = plain cram-md5
auth_verbose = yes
base_dir = /var/run/dovecot/
info_log_path = /var/log/dovecot.info
log_path = /var/log/dovecot
log_timestamp = "%Y-%m-%d %H:%M:%S "
mail_location = maildir:/home/vmail/%d/%n
passdb {
args = /etc/dovecot/passwd
driver = passwd-file
}
passdb {
args = /etc/dovecot/passwd
driver = passwd-file
}
protocols = imap pop3
service auth {
executable = /usr/libexec/dovecot/auth
unix_listener /var/spool/postfix/private/auth-client {
group = postfix
mode = 0660
user = postfix
}
user = root
}
service imap-login {
chroot = login
executable = /usr/libexec/dovecot/imap-login
user = dovecot
}
service imap {
executable = /usr/libexec/dovecot/imap
}
service pop3-login {
chroot = login
executable = /usr/libexec/dovecot/pop3-login
user = dovecot
}
service pop3 {
executable = /usr/libexec/dovecot/pop3
}
ssl = no
userdb {
args = /etc/dovecot/users
driver = passwd-file
}
userdb {
args = /etc/dovecot/users
driver = passwd-file
}
valid_chroot_dirs = /var/spool/vmail
protocol pop3 {
pop3_uidl_format = %08Xu%08Xv
}

service dovecot restart

postconf -e 'smtpd_sasl_type = dovecot'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'smtpd_sasl_path = private/auth'

service postfix restart

doveadm pw -s digest-md5 -u [email protected]
Enter new password:
Retype new password:
{DIGEST-MD5}9b9dcb4466233a9307bbc33708dffda0
doveadm pw
Enter new password:
Retype new password:
{CRAM-MD5}913331d8782236a8ecba7764a63aa27b26437fd40ca878d887f11d81245c2c6

postgrey whitelist hotmail or outlook

vi /etc/postfix/postgrey_whitelist_clients

# Do NOT greylist hotmail.com MX servers (see dig in mx hotmail.com)
/^mx[1-4]\.hotmail\.com$/

# Do NOT greylist ANY host from hotmail.com or outlook.com

#hotmail
/^.*\.hotmail\.com$/
#outlook
/^.*\.outlook\.com$/

killall postgrey
service start postgrey

Log:

postgrey[30881]: action=pass, reason=client whitelist, client_name=bay004-omc4s14.hotmail.com, client_address=65.54.190.216, sender=

You also can whitelist *.outbound.protection.outlook.com and etc

centos postfix spf check

yum install perl-Mail-SPF
yum install perl-Sys-Hostname-Long

wget https://launchpad.net/postfix-policyd-spf-perl/trunk/release2.010/+download/postfix-policyd-spf-perl-2.010.tar.gz
tar -xf postfix-policyd-spf-perl-2.010.tar.gz

mkdir /usr/lib/postfix
cp postfix-policyd-spf-perl-2.010/postfix-policyd-spf-perl /usr/lib/postfix/

perl /usr/lib/postfix/postfix-policyd-spf-perl

vim /etc/postfix/main.cf
smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination,check_policy_service unix:private/policy
policy_time_limit = 3600s

vim /etc/postfix/master.cf
policy unix – n n – 0 spawn user=nobody argv=/usr/bin/perl /usr/lib/postfix/postfix-policyd-spf-perl

service postfix restart

postfix generate ssl certificate

openssl genrsa -des3 -out mail.domain.tld.key 2048
chmod 600 mail.domain.tld.key
openssl req -new -key mail.domain.tld.key -out mail.domain.tld.csr
openssl x509 -req -days 365 -in mail.domain.tld.csr -signkey mail.domain.tld.key -out mail.domain.tld.crt
openssl rsa -in mail.domain.tld.key -out mail.domain.tld.key.nopass
mv mail.domain.tld.key.nopass mail.domain.tld.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
chmod 600 mail.domain.tld.key
chmod 600 cakey.pem
mv mail.domain.tld.key /etc/ssl/private/
mv mail.domain.tld.crt /etc/ssl/certs/
mv cakey.pem /etc/ssl/private/
mv cacert.pem /etc/ssl/certs/
postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/ssl/private/mail.domain.tld.key'
postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/mail.domain.tld.crt'
postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'
postconf -e 'myhostname = mail.example.com'