Un excellent tuto, par Reason
A Mailserver on Ubuntu 18.04: Postfix, Dovecot, MySQL
-
Postfix: sends and receives mail via the SMTP protocol. It will only relay mail on to other mailservers if the mail is sent by an authenticated user, but anyone can send mail to this server for local delivery.
-
Dovecot: a POP and IMAP server that manages local mail directories and allows users to log in and download their mail. It also handles user authentication.
-
Postgrey: greylists incoming mail, requiring unfamiliar deliverers to wait for a while and then resend. This is one of the better tools for cutting down on spam.
-
amavisd-new: a manager for organizing various antivirus and spam checking content filters.
-
Clam AntiVirus: a virus detection suite.
-
SpamAssassin: for sniffing out spam in emails.
-
Postfix Admin: a web front end for administering mail users and domains.
-
Roundcube: a webmail interface for users.
1
2
3
4
|
sudosu
apt-getinstallufw
ufwenable
ufw allow from MY_IP_ADDRESS
|
-
25 (SMTP)
-
80 (HTTP)
-
110 (POP3)
-
143 (IMAP)
-
443 (HTTPS)
-
465 (SMTPS)
-
993 (IMAPS)
-
995 (POP3S)
1
|
sudosu
|
1
|
hostname mail.example.com
|
1
|
echo « mail.example.com » > /etc/hostname
|
1
2
3
4
|
127.0.0.1 mail.example.comlocalhost
# There will be IPv6 configuration below the first line, but leave that alone.
…
|
1
2
|
apt-getinstall–assume-yesssl-cert
make-ssl-cert generate-default-snakeoil –force-overwrite
|
1
2
3
|
apt-get update
apt-get upgrade –assume-yes
apt-getinstall–assume-yeslamp-server^
|
1
2
3
4
5
|
apt-getinstall–assume-yes\
php7.2-curl \
php7.2-gd \
php7.2-mbstring \
php7.2-xml
|
1
2
3
4
5
6
7
8
9
10
11
|
aptinstall–assume-yes\
libmcrypt-dev \
php7.2-dev \
php-pear
pecl channel-update pecl.php.net
yes »| peclinstallmcrypt-1.0.1
echo’extension=mcrypt.so’>/etc/php/7.2/mods-available/mcrypt.ini
ln-s/etc/php/7.2/mods-available/mcrypt.ini/etc/php/7.2/apache2/conf.d/mcrypt.ini
ln-s/etc/php/7.2/mods-available/mcrypt.ini/etc/php/7.2/cli/conf.d/mcrypt.ini
|
1
2
|
openssl dhparam -out/etc/ssl/private/dhparams.pem 2048
chmod600/etc/ssl/private/dhparams.pem
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is ‘Full’ which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Prod
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to « EMail » to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature Off
|
1
2
|
a2enmod deflate expires headers rewrite ssl
a2ensite default-ssl
|
1
2
3
4
5
6
7
8
9
10
11
|
# Aiming for perfect forward secrecy where possible, and protecting against
# attacks such as Logjam. See:
SSLCipherSuite ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
SSLHonorCipherOrder on
# The protocols to enable.
# Available values: all, SSLv3, TLSv1, TLSv1.1, TLSv1.2
# SSL v2 is no longer supported
SSLProtocol all -SSLv2 -SSLv3
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<VirtualHost *:80>
ServerName mail.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory « /var/www/html »>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName mail.example.com
ServerAdmin webmaster@localhost
# Set the HTTP Strict Transport Security (HSTS) header to guarantee
# HTTPS for 1 Year, including subdomains, and allow this site to be
# added to the preload list.
#
# Do NOT enable this until you have the final SSL certificate in
# in place. You can get stuck.
#Header always set Strict-Transport-Security « max-age=31536000; includeSubDomains; preload »
# Prevent clickjacking by controlling who can put the site into a
# frame. Only needed for text/html, but doesn’t hurt to be applied
# generally.
Header set X-Frame-Options « SAMEORIGIN »
# Prevent mime based attacks by telling browsers that support it
# to use the declared mime type regardless of what the content looks
# like.
Header set X-Content-Type-Options « nosniff »
DocumentRoot /var/www/html
<Directory « /var/www/html »>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
#
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
#
# Use the Let’s Encrypt certificate.
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
# … more default SSL configuration …
# You will probably need to change this next Directory directive as well
# in order to match the earlier one.
<Directory « /var/www/html »>
SSLOptions +StdEnvVars
</Directory>
# … yet more default SSL configuration …
|
1
2
3
4
5
|
RewriteEngine On
# Redirect all HTTP traffic to HTTPS.
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
|
1
2
|
# Protect against Logjam attacks. See: https://weakdh.org
SSLOpenSSLConfCmd DHParameters »/etc/ssl/private/dhparams.pem »
|
1
|
service apache2 restart
|
1
|
apt-getinstall–assume-yescertbot
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# Because we are using logrotate for greater flexibility, disable the
# internal certbot logrotation.
max-log-backups = 0
# Use a 4096 bit RSA key instead of 2048.
rsa-key-size = 4096
# Set email and domains.
email = admin@example.com
domains = mail.example.com
# Text interface.
text = True
# No prompts.
non-interactive = True
# Suppress the Terms of Service agreement interaction.
agree-tos = True
# Use the webroot authenticator.
authenticator = webroot
webroot-path = /var/www/html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/bin/bash
#
# Renew the Let’s Encrypt certificate if it is time.
#
# This reads the standard /etc/letsencrypt/cli.ini.
#
# When running as a cron task, HOME may or may not be set, and
# Certbot drops stuff into ~/.local.
exportHOME= »/root »
# PATH is never what you want it it to be in a cron context, so
# make absolutely sure of it.
exportPATH= »\${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin »
# Using –no-self-upgrade suppresses the automatic update check that
# might not work in a cron context.
certbot –no-self-upgrade certonly
# Update all of the services that might now need to be using the renewed
# certificate.
service apache2 reload
service postfix reload
service dovecot reload
|
1
|
chmoda+x/etc/cron.daily/certbot-renewal
|
1
|
/etc/cron.daily/certbot-renewal
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# Set the HTTP Strict Transport Security (HSTS) header to guarantee
# HTTPS for 1 Year, including subdomains, and allow this site to be
# added to the preload list.
#
# Do NOT enable this until you have the final SSL certificate in
# in place. You can get stuck.
Header always set Strict-Transport-Security « max-age=31536000; includeSubDomains; preload »
…
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
#
# Use the Let’s Encrypt certificate.
SSLCertificateFile /etc/letsencrypt/live/mail.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mail.example.com/privkey.pem
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#
# Use the Let’s Encrypt certificate.
SSLCertificateChainFile /etc/letsencrypt/live/mail.example.com/chain.pem
|
1
|
service apache2 reload
|
1
|
apt-getinstall–assume-yesmail-server^
|
1
2
3
4
5
6
7
8
9
10
11
12
|
apt-getinstall–assume-yes\
postfix-mysql \
dovecot-mysql \
postgrey \
amavis \
clamav \
clamav-daemon \
spamassassin \
libdbi-perl \
libdbd-mysql-perl \
php7.2-imap \
postfix-policyd-spf-python
|
1
|
service apache2 restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
apt-getinstall–assume-yes\
pyzor \
razor \
arj \
cabextract \
lzop \
nomarch \
p7zip-full \
ripole \
rpm2cpio \
tnef \
unzip \
unrar-free\
zip
|
1
2
3
|
# This removes NO_ZERO_IN_DATE and NO_ZERO_DATE, which cause problems for
# Postfix Admin code, from strict mode.
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
1
|
service mysql restart
|
1
|
mysql -uroot
|
1
2
3
4
5
|
update mysql.user
setauthentication_string=password(‘rootpassword’),
plugin=’mysql_native_password’
where User=’root’;
flush privileges;
|
1
2
3
|
createdatabasemail;
createuser’mail’@’localhost’identifiedby’mailpassword’;
grantallonmail.*to’mail’@’localhost’;
|
1
2
3
4
5
6
7
|
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.2/postfixadmin-3.2.tar.gz
tar-xf postfixadmin-3.2.tar.gz
rm-f postfixadmin-3.2.tar.gz
mvpostfixadmin-3.2/srv/postfixadmin
ln-s/srv/postfixadmin/public/var/www/html/postfixadmin
mkdir-p/srv/postfixadmin/templates_c
chown-R www-data/srv/postfixadmin/templates_c
|
1
|
touch/srv/postfixadmin/config.local.php
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
// Configuration options here override those in config.inc.php.
// You have to set $CONF[‘configured’] = true; before the
// application will run.
$CONF[‘configured’] = true;
// Postfix Admin Path
// Set the location of your Postfix Admin installation here.
// YOU MUST ENTER THE COMPLETE URL e.g. http://domain.tld/postfixadmin
$CONF[‘postfix_admin_url’] = ‘https://mail.example.com/postfixadmin‘;
// Database connection details.
$CONF[‘database_type’] =’mysqli’;
$CONF[‘database_host’] =’localhost’;
$CONF[‘database_user’] =’mail’;
$CONF[‘database_password’] =’mailpassword’;
$CONF[‘database_name’] =’mail’;
// Site Admin
// Define the Site Admin’s email address below.
// This will be used to send emails from to create mailboxes and
// from Send Email / Broadcast message pages.
// Leave blank to send email from the logged-in Admin’s Email address.
$CONF[‘admin_email’] = ‘admin@example.com‘;
// Mail Server
// Hostname (FQDN) of your mail server.
// This is used to send email to Postfix in order to create mailboxes.
$CONF[‘smtp_server’] =’localhost’;
$CONF[‘smtp_port’] =’25’;
// Encrypt
// In what way do you want the passwords to be crypted?
// md5crypt = internal postfix admin md5
$CONF[‘encrypt’] =’md5crypt’;
// Default Aliases
// The default aliases that need to be created for all domains.
$CONF[‘default_aliases’] =array(
‘abuse’ => ‘admin@example.com‘,
‘hostmaster’ => ‘admin@example.com‘,
‘postmaster’ => ‘admin@example.com‘,
‘webmaster’ => ‘admin@example.com‘
);
// Footer
// Below information will be on all pages.
// If you don’t want the footer information to appear set this to ‘NO’.
$CONF[‘show_footer_text’] =’YES’;
$CONF[‘footer_text’] = ‘Return to mail.example.com‘;
$CONF[‘footer_link’] = ‘https://mail.example.com‘;
// Mailboxes
// If you want to store the mailboxes per domain set this to ‘YES’.
// Examples:
// YES: /usr/local/virtual/domain.tld/username@domain.tld
// NO: /usr/local/virtual/username@domain.tld
$CONF[‘domain_path’] =’NO’;
// If you don’t want to have the domain in your mailbox set this to ‘NO’.
// Examples:
// YES: /usr/local/virtual/domain.tld/username@domain.tld
// NO: /usr/local/virtual/domain.tld/username
// Note: If $CONF[‘domain_path’] is set to NO, this setting will be forced to YES.
$CONF[‘domain_in_mailbox’] =’YES’;
// Specify » for Dovecot and ‘INBOX.’ for Courier.
$CONF[‘create_mailbox_subdirs_prefix’]= »;
|
1
2
3
4
|
// In order to setup Postfixadmin, you MUST specify a hashed password here.
// To create the hash, visit setup.php in a browser and type a password into the field,
// on submission it will be echoed out to you as a hashed value.
$CONF[‘setup_password’] =’…a long hash string…’;
|
1
2
3
|
<Files « setup.php »>
deny from all
</Files>
|
1
2
3
4
|
useradd-r -u 150 -g mail -d/var/vmail-s/sbin/nologin-c »Virtual maildir handler »vmail
mkdir/var/vmail
chmod770/var/vmail
chownvmail:mail/var/vmail
|
1
2
|
# Database driver: mysql, pgsql, sqlite
driver = mysql
|
1
2
3
4
5
6
|
# Examples:
# connect = host=192.168.1.1 dbname=users
# connect = host=sql.example.comdbname=virtual user=virtual password=blarg
# connect = /etc/dovecot/authdb.sqlite
#
connect = host=localhost dbname=mail user=mail password=mailpassword
|
1
2
3
4
5
6
|
# Default password scheme.
#
# List of supported schemes is in
#
default_pass_scheme = MD5-CRYPT
|
1
2
3
4
5
6
7
8
|
# Define the query to obtain a user password.
#
# Note that uid 150 is the « vmail » user and gid 8 is the « mail » group.
#
password_query = \
SELECT username as user, password, ‘/var/vmail/%d/%n’ as userdb_home, \
‘maildir:/var/vmail/%d/%n’ as userdb_mail, 150 as userdb_uid, 8 as userdb_gid \
FROM mailbox WHERE username = ‘%u’ AND active = ‘1’
|
1
2
3
4
5
6
7
8
|
# Define the query to obtain user information.
#
# Note that uid 150 is the « vmail » user and gid 8 is the « mail » group.
#
user_query = \
SELECT ‘/var/vmail/%d/%n’ as home, ‘maildir:/var/vmail/%d/%n’ as mail, \
150 AS uid, 8 AS gid, concat(‘dirsize:storage=’, quota) AS quota \
FROM mailbox WHERE username = ‘%u’ AND active = ‘1’
|
1
2
3
4
5
|
# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you’re connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
disable_plaintext_auth = yes
|
1
2
3
4
5
|
# Space separated list of wanted authentication mechanisms:
# plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
# gss-spnego
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
##
## Password and user databases
##
#
# Password database is used to verify user’s password (and nothing more).
# You can have multiple passdbs and userdbs. This is useful if you want to
# allow both system users (/etc/passwd) and virtual users to login without
# duplicating the system users into virtual database.
#
# <doc/wiki/PasswordDatabase.txt>
#
# User database specifies where mails are located and what user/group IDs
# own them. For single-UID configuration use « static » userdb.
#
# <doc/wiki/UserDatabase.txt>
#!include auth-deny.conf.ext
#!include auth-master.conf.ext
#!include auth-system.conf.ext
# Use the SQL database configuration for authentication rather than
# any of these others.
!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# Location for users’ mailboxes. The default is empty, which means that Dovecot
# tries to find the mailboxes automatically. This won’t work if the user
# doesn’t yet have any mail, so you should explicitly tell Dovecot the full
# location.
#
# If you’re using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn’t enough. You’ll also need to tell Dovecot where the other mailboxes are
# kept. This is called the « root mail directory », and it must be the first
# path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
# %u – username
# %n – user part in user@domain, same as %u if there’s no domain
# %d – domain part in user@domain, empty if there’s no domain
# %h – home directory
#
# See doc/wiki/Variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
mail_location = maildir:/var/vmail/%d/%n
|
1
2
3
4
5
|
# System user and group used to access mails. If you use multiple, userdb
# can override these by returning uid or gid fields. You can use either numbers
# or names. <doc/wiki/UserIds.txt>
mail_uid = vmail
mail_gid = mail
|
1
2
3
4
5
6
7
8
|
# Valid UID range for users, defaults to 500 and above. This is mostly
# to make sure that users can’t log in as daemons or other system users.
# Note that denying root logins is hardcoded to dovecot binary and can’t
# be done even if first_valid_uid is set to 0.
#
# Use the vmail user uid here.
first_valid_uid = 150
last_valid_uid = 150
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
ssl = yes
# PEM encoded X.509 SSL/TLS certificate and private key. They’re opened before
# dropping root privileges, so keep the key file unreadable by anyone but
# root. Included doc/mkcert.sh can be used to easily generate self-signed
# certificate, just make sure to update the domains in dovecot-openssl.cnf
#
# The generated snakeoil certificate:
#ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
#ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
# Let’s Encrypt certificate:
ssl_cert = </etc/letsencrypt/live/mail.example.com/cert.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
# If key file is password protected, give the password here. Alternatively
# give it when starting dovecot with -p parameter. Since this file is often
# world-readable, you may want to place this setting instead to a different
# root owned 0600 file by using ssl_key_password = <path.
#ssl_key_password =
# PEM encoded trusted certificate authority. Set this only if you intend to use
# ssl_verify_client_cert=yes. The file should contain the CA certificate(s)
# followed by the matching CRL(s). (e.g. ssl_ca = </etc/ssl/certs/ca.pem)
ssl_ca = </etc/letsencrypt/live/mail.example.com/chain.pem
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# DH parameters length to use. In light of Logjam, has to be 2048 or more.
ssl_dh_parameters_length = 2048
# SSL protocols to use. Don’t use the no-longer secure protocols.
ssl_protocols = !SSLv2 !SSLv3
# SSL ciphers to use. See:
ssl_cipher_list = ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
# Prefer the server’s order of ciphers over client’s.
ssl_prefer_server_ciphers = yes
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
service auth {
# auth_socket_path points to this userdb socket by default. It’s typically
# used by dovecot-lda, doveadm, possibly imap process, etc. Users that have
# full permissions to this socket are able to get a list of all usernames and
# get the results of everyone’s userdb lookups.
#
# The default 0666 mode allows anyone to connect to the socket, but the
# userdb lookups will succeed only if the userdb returns an « uid » field that
# matches the caller process’s UID. Also if caller’s uid or gid matches the
# socket’s uid or gid the lookup succeeds. Anything else causes a failure.
#
# To give the caller full permissions to lookup all users, set the mode to
# something else than 0666 and Dovecot lets the kernel enforce the
# permissions (e.g. 0777 allows everyone full permissions).
unix_listener auth-userdb {
mode = 0666
user = vmail
group = mail
}
unix_listener /var/spool/postfix/private/auth {
mode = 0666
# Assuming the default Postfix user and group
user = postfix
group = postfix
}
|
1
2
3
|
# Address to use when sending rejection mails.
# Default is postmaster@<your domain>.
postmaster_address = postmaster@example.com
|
1
2
|
chown-R vmail:dovecot/etc/dovecot
chmod-R o-rwx/etc/dovecot
|
1
2
|
adduser clamav amavis
adduser amavis clamav
|
1
2
3
|
# Needed to allow things to work with Amavis, when both amavis and clamav
# users are added to one another’s groups.
AllowSupplementaryGroups true
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
use strict;
# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.
#
# Default antivirus checking mode
# Please note, that anti-virus checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:
@bypass_virus_checks_maps = (
\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
#
# Default SPAM checking mode
# Please note, that anti-spam checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
1; # ensure a defined return
|
1
2
|
# Change to one to enable spamd
ENABLED=1
|
1
2
3
4
|
# Cronjob
# Set to anything but 0 to enable the cron job to automatically update
# spamassassin’s rules on a nightly basis
CRON=1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
use strict;
#
# Place your configuration directives here. They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#
# Three concurrent processes. This should fit into the RAM available on an
# AWS micro instance. This has to match the number of processes specified
# for Amavis in /etc/postfix/master.cf.
$max_servers = 3;
# Add spam info headers if at or above that level – this ensures they
# are always added.
$sa_tag_level_deflt = -9999;
# Check the database to see if mail is for local delivery, and thus
# should be spam checked.
@lookup_sql_dsn = (
[‘DBI:mysql:database=mail;host=127.0.0.1;port=3306’,
‘mail’,
‘mailpassword’]);
$sql_select_policy = ‘SELECT domain from domain WHERE CONCAT(« @ »,domain) IN (%k)’;
# Uncomment to bump up the log level when testing.
# $log_level = 2;
#———— Do not modify anything below this line ————-
1; # ensure a defined return
|
1
|
freshclam
|
1
2
3
|
service clamav-daemon restart
service amavis restart
service spamassassin restart
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT goto FROM alias,alias_domain
WHERE alias_domain.alias_domain = ‘%d’
AND alias.address=concat(‘%u’, ‘@’, alias_domain.target_domain)
AND alias.active = 1
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
table = alias
select_field = goto
where_field = address
additional_conditions = and active = ‘1’
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = ‘0’ and active = ‘1’
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT maildir FROM mailbox, alias_domain
WHERE alias_domain.alias_domain = ‘%d’
AND mailbox.username=concat(‘%u’, ‘@’, alias_domain.target_domain )
AND mailbox.active = 1
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
table = mailbox
select_field = CONCAT(domain, ‘/’, local_part)
where_field = username
additional_conditions = and active = ‘1’
|
1
2
3
4
5
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT goto FROM alias WHERE address=’%s’
|
1
2
3
4
5
6
|
/^Received:/ IGNORE
/^User-Agent:/ IGNORE
/^X-Mailer:/ IGNORE
/^X-Originating-IP:/ IGNORE
/^x-cr-[a-z]*:/ IGNORE
/^Thread-Index:/ IGNORE
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# The first text sent to a connecting process.
smtpd_banner = $myhostname ESMTP $mail_name
biff = no
# appending .domain is the MUA’s job.
append_dot_mydomain = no
readme_directory = no
# ———————————
# SASL parameters
# ———————————
# Use Dovecot to authenticate.
smtpd_sasl_type = dovecot
# Referring to /var/spool/postfix/private/auth
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
smtpd_sasl_authenticated_header = yes
# ———————————
# TLS parameters
# ———————————
# The default snakeoil certificate.
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
# Let’s Encrypt certificate.
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.example.com/cert.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_tls_CAfile=/etc/letsencrypt/live/mail.example.com/chain.pem
# Ensure we’re not using no-longer-secure protocols.
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# Note that forcing use of TLS is going to cause breakage – most mail servers
# don’t offer it and so delivery will fail, both incoming and outgoing. This is
# unfortunate given what various governmental agencies are up to these days.
#
# Enable (but don’t force) all incoming smtp connections to use TLS.
smtpd_tls_security_level = may
# Enable (but don’t force) all outgoing smtp connections to use TLS.
smtp_tls_security_level = may
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
# ———————————
# TLS Updates relating to Logjam SSL attacks.
# ———————————
smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC4, MD5, PSK, aECDH, EDH-DSS-DES-CBC3-SHA, EDH-RSA-DES-CDC3-SHA, KRB5-DE5, CBC3-SHA
smtpd_tls_dh1024_param_file = /etc/ssl/private/dhparams.pem
# ———————————
# SMTPD parameters
# ———————————
# Uncomment the next line to generate « delayed mail » warnings
#delay_warning_time = 4h
# will it be a permanent error or temporary
unknown_local_recipient_reject_code = 450
# how long to keep message on queue before return as failed.
maximal_queue_lifetime = 7d
# max and min time in seconds between retries if connection failed
minimal_backoff_time = 1000s
maximal_backoff_time = 8000s
# how long to wait when servers connect before receiving rest of data
smtp_helo_timeout = 60s
# how many address can be used in one message.
# effective stopper to mass spammers, accidental copy in whole address list
# but may restrict intentional mail shots.
smtpd_recipient_limit = 16
# how many error before back off.
smtpd_soft_error_limit = 3
# how many max errors before blocking it.
smtpd_hard_error_limit = 12
# This next set are important for determining who can send mail and relay mail
# to other servers. It is very important to get this right – accidentally producing
# an open relay that allows unauthenticated sending of mail is a Very Bad Thing.
#
# You are encouraged to read up on what exactly each of these options accomplish.
# Requirements for the HELO statement
smtpd_helo_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_hostname, reject_invalid_hostname, permit
# Requirements for the sender details. Note that the order matters.
smtpd_sender_restrictions = permit_mynetworks, reject_authenticated_sender_login_mismatch, permit_sasl_authenticated, warn_if_reject reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit
# Requirements for the connecting server
smtpd_client_restrictions = reject_rbl_client sbl.spamhaus.org, reject_rbl_client blackholes.easynet.nl
# Requirement for the recipient address. Note that the entry for
# « check_policy_service inet:127.0.0.1:10023 » enables Postgrey.
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service unix:private/policy-spf, check_policy_service inet:127.0.0.1:10023, permit
smtpd_data_restrictions = reject_unauth_pipelining
# This is a new option as of Postfix 2.10, and is required in addition to
# smtpd_recipient_restrictions for things to work properly in this setup.
smtpd_relay_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service unix:private/policy-spf, check_policy_service inet:127.0.0.1:10023, permit
# require proper helo at connections
smtpd_helo_required = yes
# waste spammers time before rejecting them
smtpd_delay_reject = yes
disable_vrfy_command = yes
# ———————————
# General host and delivery info
# ———————————-
myhostname = mail.example.com
myorigin = /etc/hostname
# Some people see issues when setting mydestination explicitly to the server
# subdomain, while leaving it empty generally doesn’t hurt. So it is left empty here.
# mydestination = mail.example.com, localhost
mydestination =
# If you have a separate web server that sends outgoing mail through this
# mailserver, you may want to add its IP address to the space-delimited list in
# mynetworks, e.g. as 10.10.10.10/32.
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
mynetworks_style = host
# This specifies where the virtual mailbox folders will be located.
virtual_mailbox_base = /var/vmail
# This is for the mailbox location for each user. The domainaliases
# map allows us to make use of Postfix Admin’s domain alias feature.
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/mysql_virtual_mailbox_domainaliases_maps.cf
# and their user id
virtual_uid_maps = static:150
# and group id
virtual_gid_maps = static:8
# This is for aliases. The domainaliases map allows us to make
# use of Postfix Admin’s domain alias feature.
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/mysql_virtual_alias_domainaliases_maps.cf
# This is for domain lookups.
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
# Used in conjunction with reject_authenticated_sender_login_mismatch to
# verify that the sender is sending with their own address, or with one
# of the aliases mapped to that address.
smtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_login_maps.cf
# ———————————
# Integration with other packages
# —————————————
# Tell postfix to hand off mail to the definition for dovecot in master.cf
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
# Use amavis for virus and spam scanning
content_filter = amavis:[127.0.0.1]:10024
# Settings for checking SPF to cut down spam.
policy-spf_time_limit = 3600s
# ———————————
# Header manipulation
# ————————————–
# Getting rid of unwanted headers. See: https://posluns.com/guides/header-removal/
header_checks = regexp:/etc/postfix/header_checks
# getting rid of x-original-to
enable_original_recipient = no
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: « man 5 master » or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute « postfix reload » after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (no) (never) (100)
# ==========================================================================
smtp inet n – y – – smtpd
#smtp inet n – y – 1 postscreen
#smtpd pass – – y – – smtpd
#dnsblog unix – – y – 0 dnsblog
#tlsproxy unix – – y – 0 tlsproxy
# SMTP with TLS on port 587. Currently commented.
#submission inet n – y – – smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_enforce_tls=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject
# -o smtpd_sasl_tls_security_options=noanonymous
# SMTP over SSL on port 465.
smtps inet n – y – – smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject
-o smtpd_sasl_security_options=noanonymous,noplaintext
-o smtpd_sasl_tls_security_options=noanonymous
#628 inet n – y – – qmqpd
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
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
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
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix – n n – – pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing « lmtp » master.cfentry.
#
# Specify in cyrus.conf:
# lmtp cmd= »lmtpd -a » listen= »localhost:lmtp » proto=tcp4
#
# Specify in main.cfone or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix – n n – – pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix – n n – – pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix – n n – – pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender – $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
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}
# The next two entries integrate with Amavis for anti-virus/spam checks.
amavis unix – – y – 3 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
127.0.0.1:10025 inet n – y – – smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters
# Integration with Dovecot – hand mail over to it for local delivery, and
# run the process under the vmail user and mail group.
dovecot unix – n n – – pipe
flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/dovecot-lda -d $(recipient)
# Integration with the SPF check package.
policy-spf unix – n n – – spawn
user=nobody argv=/usr/bin/policyd-spf
|
1
2
3
4
5
|
service postfix restart
service spamassassin restart
service clamav-daemon restart
service amavis restart
service dovecot restart
|
1
|
apt-getinstall–assume-yesmonit
|
1
2
3
4
5
6
7
|
check process amavisd with pidfile /var/run/amavis/amavisd.pid
every 5 cycles
group mail
start program = « /usr/sbin/service amavis start »
stop program = « /usr/sbin/service amavis stop »
if failed port 10024 protocol smtp then restart
if 5 restarts within 25 cycles then timeout
|
1
2
3
4
5
6
7
8
9
10
11
|
check process apache2 with pidfile /var/run/apache2/apache2.pid
group www
start program = « /usr/sbin/service apache2 start »
stop program = « /usr/sbin/service apache2 stop »
if failed host localhost port 80 protocol http
with timeout 10 seconds
then restart
if failed host localhost port 443 type tcpssl protocol http
with timeout 10 seconds
then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
6
7
8
9
10
|
check process dovecot with pidfile /var/run/dovecot/master.pid
group mail
start program = « /usr/sbin/service dovecot start »
stop program = « /usr/sbin/service dovecot stop »
group mail
# We’d like to use this line, but see:
#if failed port 993 type tcpssl sslauto protocol imap for 5 cycles then restart
if failed port 993 for 5 cycles then restart
if 5 restarts within 25 cycles then timeout
|
1
2
3
4
5
6
|
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
start program = « /usr/sbin/service mysql start »
stop program = « /usr/sbin/service mysql stop »
if failed host localhost port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
6
|
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = « /usr/sbin/service postfix start »
stop program = « /usr/sbin/service postfix stop »
if failed port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
|
check process spamassassin with pidfile /var/run/spamd.pid
group mail
start program = « /usr/sbin/service spamassassin start »
stop program = « /usr/sbin/service spamassassin stop »
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
|
check process sshd with pidfile /var/run/sshd.pid
start program « /usr/sbin/service ssh start »
stop program « /usr/sbin/service ssh stop »
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
6
7
8
9
10
11
12
|
## Monit has an embedded HTTP interface which can be used to view status of
## services monitored and manage services from a web interface. The HTTP
## interface is also required if you want to issue Monit commands from the
## command line, such as ‘monit status’ or ‘monit restart service’ The reason
## for this is that the Monit client uses the HTTP interface to send these
## commands to a running Monit daemon. See the Monit Wiki if you want to
## enable SSL for the HTTP interface.
#
set httpd port 2812 and
use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
# allow admin:monit # require user ‘admin’ with password ‘monit’
|
1
|
service monit restart
|
1
|
monit status
|
1
2
|
# monit monitor <name>, e.g.:
monit monitor mysqld
|
1
2
3
4
5
6
7
8
|
apt-getinstall–assume-yes\
roundcube \
roundcube-plugins \
php7.2-mail \
php-mime-type\
php-mail-mime \
php7.2-intl \
php7.2-zip
|
1
|
pearinstallNet_IDNA2-0.2.0 Mail_mimeDecode-1.5.6
|
1
|
service apache2 restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// The mail host chosen to perform the log-in.
// Leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// Supported replacement variables:
// %n – hostname ($_SERVER[‘SERVER_NAME’])
// %t – hostname without the first part
// %d – domain (http hostname $_SERVER[‘HTTP_HOST’] without the first part)
// %s – domain name after the ‘@’ from e-mail address provided at login screen
// For example %n = mail.domain.tld, %t = domain.tld
// WARNING: After hostname change update of mail_host column in users table is
// required to match old user data records with the new host.
$config[‘default_host’] =’localhost’;
// SMTP server host (for sending mails).
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// If left blank, the PHP mail() function is used
// Supported replacement variables:
// %h – user’s IMAP hostname
// %n – hostname ($_SERVER[‘SERVER_NAME’])
// %t – hostname without the first part
// %d – domain (http hostname $_SERVER[‘HTTP_HOST’] without the first part)
// %z – IMAP domain (IMAP hostname without the first part)
// For example %n = mail.domain.tld, %t = domain.tld
$config[‘smtp_server’] =’localhost’;
|
1
2
3
4
5
6
7
8
9
10
|
// enforce connections over https
// with this option enabled, all non-secure connections will be redirected.
// set the port for the ssl connection as value of this option if it differs from the default 443
$config[‘force_https’] = true;
// Type of IMAP indexes cache. Supported values: ‘db’, ‘apc’ and ‘memcache’.
$config[‘imap_cache’] =’db’;
// Backend to use for session storage. Can either be ‘db’ (default) or ‘memcache’
$config[‘session_storage’] =’db’;
|
1
2
3
4
5
|
// this key is used to encrypt the users imap password which is stored
// in the session record (and the client cookie if remember password is enabled).
// please provide a string of exactly 24 chars.
// YOUR KEY MUST BE DIFFERENT THAN THE SAMPLE VALUE FOR SECURITY REASONS
$config[‘des_key’] =’enter a unique value here’;
|
1
|
ln-s/var/lib/roundcube/var/www/html/roundcube
|
1
|
mv/var/www/html/index.html/var/www/html/index.bak.html
|
1
2
3
4
5
6
7
8
|
RewriteEngine On
# Redirect all HTTP traffic to HTTPS.
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# Send / to /roundcube.
RewriteRule ^/?$ /roundcube [L]
|
1
|
« v=spf1 a mx -all »
|
1
|
dig google.comtxt
|
1
|
apt-getinstall–assume-yesopendkim opendkim-tools
|
1
2
3
|
1
|
Socket inet:8891@localhost
|
1
|
SOCKET=inet:8891@localhost
|
1
2
3
4
5
6
7
|
# ————————————–
# DKIM
# ————————————–
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
|
1
|
op/endkim-genkey -t -s dkim -d example.com
|
1
2
3
|
mvdkim.private/etc/postfix/dkim.key
chmod660/etc/postfix/dkim.key
chownroot:opendkim/etc/postfix/dkim.key
|
1
2
|
service opendkim start
service postfix restart
|
1
2
|
dkim._domainkey IN TXT ( « v=DKIM1; k=rsa; t=y; «
« p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9rulKo58JIb5h+3MMEnYhlnbuVgRoA4w68R/X7qA2Lfv3RpdrrUb+r7KxemIo6PUIOm6uZ5OymhBgpJ0LAWBHBSJjnFmDXNajSgxMOcvkpgmVCW1/k1kxK864WVVSyFVQPyUImqklY+ws4u+mog3PSbuq2J8NFAnvSwzMg3vT1QIDAQAB » ; —– DKIM key mail for example.com
|
1
|
« v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9rulKo58JIb5h+3MMEnYhlnbuVgRoA4w68R/X7qA2Lfv3RpdrrUb+r7KxemIo6PUIOm6uZ5OymhBgpJ0LAWBHBSJjnFmDXNajSgxMOcvkpgmVCW1/k1kxK864WVVSyFVQPyUImqklY+ws4u+mog3PSbuq2J8NFAnvSwzMg3vT1QIDAQAB »
|
1
|
dig dkim._domainkey.twitter.comtxt
|
1
2
3
4
5
|
check process opendkim with pidfile /var/run/opendkim/opendkim.pid
group mail
start program = « /etc/init.d/opendkim start »
stop program = « /etc/init.d/opendkim stop »
if 5 restarts within 5 cycles then timeout
|
1
|
service monit restart
|
1
2
3
4
|
Domain *
KeyFile /etc/postfix/dkim.key
Selector dkim
SOCKET inet:8891@localhost
|
1
2
|
cp/etc/postgrey/whitelist_clients/etc/postfix/postgrey_whitelist_clients
cp/etc/postgrey/whitelist_recipients/etc/postfix/postgrey_whitelist_recipients
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# postgrey startup options, created for Debian
# you may want to set
# –delay=N how long to greylist, seconds (default: 300)
# –max-age=N delete old entries after N days (default: 35)
# see also the postgrey(8) manpage
POSTGREY_OPTS= »–inet=10023″
POSTGREY_OPTS= »$POSTGREY_OPTS –whitelist-clients=/etc/postgrey/whitelist_clients »
POSTGREY_OPTS= »$POSTGREY_OPTS –whitelist-recipients=/etc/postgrey/whitelist_recipients »
# the –greylist-text commandline argument can not be easily passed through
# POSTGREY_OPTS when it contains spaces. So, insert your text here:
#POSTGREY_TEXT= »Your customized rejection message here »
|
1
2
3
4
5
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ‘1’ AND active = ‘1’
|
1
2
3
|
# This is a backup MX server, and this line tells Postfix
# where to send the mail.
relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf
|
1
2
3
|
1
2
3
4
5
|
// Quota
// When you want to enforce quota for your mailbox users set this to ‘YES’.
$CONF[‘quota’] =’YES’;
// You can either use ‘1024000’ or ‘1048576’
$CONF[‘quota_multiplier’] =’1024000′;
|
1
2
3
4
5
6
7
8
9
10
11
12
|
// Optional:
// Show used quotas from Dovecot dictionary backend in virtual
// mailbox listing.
// See: DOCUMENTATION/DOVECOT.txt
//
$CONF[‘used_quotas’] =’YES’;
// if you use dovecot >= 1.2, set this to yes.
// Note about dovecot config: table « quota » is for 1.0 & 1.1,
// table « quota2 » is for dovecot 1.2 and newer
$CONF[‘new_quota_table’] =’YES’;
|
1
2
3
4
5
6
7
8
9
10
|
# Replace 111.111.111.111/32 with your desired list of client IP address
# ranges which will bypass checks.
@mynetworks = qw( 127.0.0.0/8 [::1] 111.111.111.111/32 );
# Rules for clients defined in @mynetworks
$policy_bank{‘MYNETS’} = {
bypass_spam_checks_maps => [1], # don’t spam-check internal mail
bypass_banned_checks_maps => [1], # don’t banned-check internal mail
bypass_header_checks_maps => [1], # don’t header-check internal mail
};
|
Further, it is apparently the case that all email traffic between mail servers is being recorded by various governmental agencies. Unfortunately the present state of SMTP in the wild is that many or most mail servers do not implement the ability to pass emails over an encrypted connection: so while it’s easy to setup and enforce encryption for POP, IMAP, and webmail connections between users and the mail server, email traffic between mail servers is often plain text. Forcing your server to only use encrypted connections with other servers will mean that a large fraction of your email traffic in both directions will be rejected. Thus the configuration provided for Postfix in this post is for optional encryption – emails sent and received will be encrypted if the mail server on the other end of the connection can support it.
A Mailserver on Ubuntu 18.04: Postfix, Dovecot, MySQL
-
Postfix: sends and receives mail via the SMTP protocol. It will only relay mail on to other mailservers if the mail is sent by an authenticated user, but anyone can send mail to this server for local delivery.
-
Dovecot: a POP and IMAP server that manages local mail directories and allows users to log in and download their mail. It also handles user authentication.
-
Postgrey: greylists incoming mail, requiring unfamiliar deliverers to wait for a while and then resend. This is one of the better tools for cutting down on spam.
-
amavisd-new: a manager for organizing various antivirus and spam checking content filters.
-
Clam AntiVirus: a virus detection suite.
-
SpamAssassin: for sniffing out spam in emails.
-
Postfix Admin: a web front end for administering mail users and domains.
-
Roundcube: a webmail interface for users.
1
2
3
4
|
sudosu
apt-getinstallufw
ufwenable
ufw allow from MY_IP_ADDRESS
|
-
25 (SMTP)
-
80 (HTTP)
-
110 (POP3)
-
143 (IMAP)
-
443 (HTTPS)
-
465 (SMTPS)
-
993 (IMAPS)
-
995 (POP3S)
1
|
sudosu
|
1
|
hostname mail.example.com
|
1
|
echo « mail.example.com » > /etc/hostname
|
1
2
3
4
|
127.0.0.1 mail.example.comlocalhost
# There will be IPv6 configuration below the first line, but leave that alone.
…
|
1
2
|
apt-getinstall–assume-yesssl-cert
make-ssl-cert generate-default-snakeoil –force-overwrite
|
1
2
3
|
apt-get update
apt-get upgrade –assume-yes
apt-getinstall–assume-yeslamp-server^
|
1
2
3
4
5
|
apt-getinstall–assume-yes\
php7.2-curl \
php7.2-gd \
php7.2-mbstring \
php7.2-xml
|
1
2
3
4
5
6
7
8
9
10
11
|
aptinstall–assume-yes\
libmcrypt-dev \
php7.2-dev \
php-pear
pecl channel-update pecl.php.net
yes »| peclinstallmcrypt-1.0.1
echo’extension=mcrypt.so’>/etc/php/7.2/mods-available/mcrypt.ini
ln-s/etc/php/7.2/mods-available/mcrypt.ini/etc/php/7.2/apache2/conf.d/mcrypt.ini
ln-s/etc/php/7.2/mods-available/mcrypt.ini/etc/php/7.2/cli/conf.d/mcrypt.ini
|
1
2
|
openssl dhparam -out/etc/ssl/private/dhparams.pem 2048
chmod600/etc/ssl/private/dhparams.pem
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is ‘Full’ which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Prod
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to « EMail » to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature Off
|
1
2
|
a2enmod deflate expires headers rewrite ssl
a2ensite default-ssl
|
1
2
3
4
5
6
7
8
9
10
11
|
# Aiming for perfect forward secrecy where possible, and protecting against
# attacks such as Logjam. See:
SSLCipherSuite ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
SSLHonorCipherOrder on
# The protocols to enable.
# Available values: all, SSLv3, TLSv1, TLSv1.1, TLSv1.2
# SSL v2 is no longer supported
SSLProtocol all -SSLv2 -SSLv3
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<VirtualHost *:80>
ServerName mail.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory « /var/www/html »>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName mail.example.com
ServerAdmin webmaster@localhost
# Set the HTTP Strict Transport Security (HSTS) header to guarantee
# HTTPS for 1 Year, including subdomains, and allow this site to be
# added to the preload list.
#
# Do NOT enable this until you have the final SSL certificate in
# in place. You can get stuck.
#Header always set Strict-Transport-Security « max-age=31536000; includeSubDomains; preload »
# Prevent clickjacking by controlling who can put the site into a
# frame. Only needed for text/html, but doesn’t hurt to be applied
# generally.
Header set X-Frame-Options « SAMEORIGIN »
# Prevent mime based attacks by telling browsers that support it
# to use the declared mime type regardless of what the content looks
# like.
Header set X-Content-Type-Options « nosniff »
DocumentRoot /var/www/html
<Directory « /var/www/html »>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
#
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
#
# Use the Let’s Encrypt certificate.
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
# … more default SSL configuration …
# You will probably need to change this next Directory directive as well
# in order to match the earlier one.
<Directory « /var/www/html »>
SSLOptions +StdEnvVars
</Directory>
# … yet more default SSL configuration …
|
1
2
3
4
5
|
RewriteEngine On
# Redirect all HTTP traffic to HTTPS.
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
|
1
2
|
# Protect against Logjam attacks. See: https://weakdh.org
SSLOpenSSLConfCmd DHParameters »/etc/ssl/private/dhparams.pem »
|
1
|
service apache2 restart
|
1
|
apt-getinstall–assume-yescertbot
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# Because we are using logrotate for greater flexibility, disable the
# internal certbot logrotation.
max-log-backups = 0
# Use a 4096 bit RSA key instead of 2048.
rsa-key-size = 4096
# Set email and domains.
email = admin@example.com
domains = mail.example.com
# Text interface.
text = True
# No prompts.
non-interactive = True
# Suppress the Terms of Service agreement interaction.
agree-tos = True
# Use the webroot authenticator.
authenticator = webroot
webroot-path = /var/www/html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/bin/bash
#
# Renew the Let’s Encrypt certificate if it is time.
#
# This reads the standard /etc/letsencrypt/cli.ini.
#
# When running as a cron task, HOME may or may not be set, and
# Certbot drops stuff into ~/.local.
exportHOME= »/root »
# PATH is never what you want it it to be in a cron context, so
# make absolutely sure of it.
exportPATH= »\${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin »
# Using –no-self-upgrade suppresses the automatic update check that
# might not work in a cron context.
certbot –no-self-upgrade certonly
# Update all of the services that might now need to be using the renewed
# certificate.
service apache2 reload
service postfix reload
service dovecot reload
|
1
|
chmoda+x/etc/cron.daily/certbot-renewal
|
1
|
/etc/cron.daily/certbot-renewal
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# Set the HTTP Strict Transport Security (HSTS) header to guarantee
# HTTPS for 1 Year, including subdomains, and allow this site to be
# added to the preload list.
#
# Do NOT enable this until you have the final SSL certificate in
# in place. You can get stuck.
Header always set Strict-Transport-Security « max-age=31536000; includeSubDomains; preload »
…
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
#
# Use the Let’s Encrypt certificate.
SSLCertificateFile /etc/letsencrypt/live/mail.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mail.example.com/privkey.pem
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#
# Use the Let’s Encrypt certificate.
SSLCertificateChainFile /etc/letsencrypt/live/mail.example.com/chain.pem
|
1
|
service apache2 reload
|
1
|
apt-getinstall–assume-yesmail-server^
|
1
2
3
4
5
6
7
8
9
10
11
12
|
apt-getinstall–assume-yes\
postfix-mysql \
dovecot-mysql \
postgrey \
amavis \
clamav \
clamav-daemon \
spamassassin \
libdbi-perl \
libdbd-mysql-perl \
php7.2-imap \
postfix-policyd-spf-python
|
1
|
service apache2 restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
apt-getinstall–assume-yes\
pyzor \
razor \
arj \
cabextract \
lzop \
nomarch \
p7zip-full \
ripole \
rpm2cpio \
tnef \
unzip \
unrar-free\
zip
|
1
2
3
|
# This removes NO_ZERO_IN_DATE and NO_ZERO_DATE, which cause problems for
# Postfix Admin code, from strict mode.
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
1
|
service mysql restart
|
1
|
mysql -uroot
|
1
2
3
4
5
|
update mysql.user
setauthentication_string=password(‘rootpassword’),
plugin=’mysql_native_password’
where User=’root’;
flush privileges;
|
1
2
3
|
createdatabasemail;
createuser’mail’@’localhost’identifiedby’mailpassword’;
grantallonmail.*to’mail’@’localhost’;
|
1
2
3
4
5
6
7
|
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.2/postfixadmin-3.2.tar.gz
tar-xf postfixadmin-3.2.tar.gz
rm-f postfixadmin-3.2.tar.gz
mvpostfixadmin-3.2/srv/postfixadmin
ln-s/srv/postfixadmin/public/var/www/html/postfixadmin
mkdir-p/srv/postfixadmin/templates_c
chown-R www-data/srv/postfixadmin/templates_c
|
1
|
touch/srv/postfixadmin/config.local.php
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
// Configuration options here override those in config.inc.php.
// You have to set $CONF[‘configured’] = true; before the
// application will run.
$CONF[‘configured’] = true;
// Postfix Admin Path
// Set the location of your Postfix Admin installation here.
// YOU MUST ENTER THE COMPLETE URL e.g. http://domain.tld/postfixadmin
$CONF[‘postfix_admin_url’] = ‘https://mail.example.com/postfixadmin‘;
// Database connection details.
$CONF[‘database_type’] =’mysqli’;
$CONF[‘database_host’] =’localhost’;
$CONF[‘database_user’] =’mail’;
$CONF[‘database_password’] =’mailpassword’;
$CONF[‘database_name’] =’mail’;
// Site Admin
// Define the Site Admin’s email address below.
// This will be used to send emails from to create mailboxes and
// from Send Email / Broadcast message pages.
// Leave blank to send email from the logged-in Admin’s Email address.
$CONF[‘admin_email’] = ‘admin@example.com‘;
// Mail Server
// Hostname (FQDN) of your mail server.
// This is used to send email to Postfix in order to create mailboxes.
$CONF[‘smtp_server’] =’localhost’;
$CONF[‘smtp_port’] =’25’;
// Encrypt
// In what way do you want the passwords to be crypted?
// md5crypt = internal postfix admin md5
$CONF[‘encrypt’] =’md5crypt’;
// Default Aliases
// The default aliases that need to be created for all domains.
$CONF[‘default_aliases’] =array(
‘abuse’ => ‘admin@example.com‘,
‘hostmaster’ => ‘admin@example.com‘,
‘postmaster’ => ‘admin@example.com‘,
‘webmaster’ => ‘admin@example.com‘
);
// Footer
// Below information will be on all pages.
// If you don’t want the footer information to appear set this to ‘NO’.
$CONF[‘show_footer_text’] =’YES’;
$CONF[‘footer_text’] = ‘Return to mail.example.com‘;
$CONF[‘footer_link’] = ‘https://mail.example.com‘;
// Mailboxes
// If you want to store the mailboxes per domain set this to ‘YES’.
// Examples:
// YES: /usr/local/virtual/domain.tld/username@domain.tld
// NO: /usr/local/virtual/username@domain.tld
$CONF[‘domain_path’] =’NO’;
// If you don’t want to have the domain in your mailbox set this to ‘NO’.
// Examples:
// YES: /usr/local/virtual/domain.tld/username@domain.tld
// NO: /usr/local/virtual/domain.tld/username
// Note: If $CONF[‘domain_path’] is set to NO, this setting will be forced to YES.
$CONF[‘domain_in_mailbox’] =’YES’;
// Specify » for Dovecot and ‘INBOX.’ for Courier.
$CONF[‘create_mailbox_subdirs_prefix’]= »;
|
1
2
3
4
|
// In order to setup Postfixadmin, you MUST specify a hashed password here.
// To create the hash, visit setup.php in a browser and type a password into the field,
// on submission it will be echoed out to you as a hashed value.
$CONF[‘setup_password’] =’…a long hash string…’;
|
1
2
3
|
<Files « setup.php »>
deny from all
</Files>
|
1
2
3
4
|
useradd-r -u 150 -g mail -d/var/vmail-s/sbin/nologin-c »Virtual maildir handler »vmail
mkdir/var/vmail
chmod770/var/vmail
chownvmail:mail/var/vmail
|
1
2
|
# Database driver: mysql, pgsql, sqlite
driver = mysql
|
1
2
3
4
5
6
|
# Examples:
# connect = host=192.168.1.1 dbname=users
# connect = host=sql.example.comdbname=virtual user=virtual password=blarg
# connect = /etc/dovecot/authdb.sqlite
#
connect = host=localhost dbname=mail user=mail password=mailpassword
|
1
2
3
4
5
6
|
# Default password scheme.
#
# List of supported schemes is in
#
default_pass_scheme = MD5-CRYPT
|
1
2
3
4
5
6
7
8
|
# Define the query to obtain a user password.
#
# Note that uid 150 is the « vmail » user and gid 8 is the « mail » group.
#
password_query = \
SELECT username as user, password, ‘/var/vmail/%d/%n’ as userdb_home, \
‘maildir:/var/vmail/%d/%n’ as userdb_mail, 150 as userdb_uid, 8 as userdb_gid \
FROM mailbox WHERE username = ‘%u’ AND active = ‘1’
|
1
2
3
4
5
6
7
8
|
# Define the query to obtain user information.
#
# Note that uid 150 is the « vmail » user and gid 8 is the « mail » group.
#
user_query = \
SELECT ‘/var/vmail/%d/%n’ as home, ‘maildir:/var/vmail/%d/%n’ as mail, \
150 AS uid, 8 AS gid, concat(‘dirsize:storage=’, quota) AS quota \
FROM mailbox WHERE username = ‘%u’ AND active = ‘1’
|
1
2
3
4
5
|
# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you’re connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
disable_plaintext_auth = yes
|
1
2
3
4
5
|
# Space separated list of wanted authentication mechanisms:
# plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
# gss-spnego
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
##
## Password and user databases
##
#
# Password database is used to verify user’s password (and nothing more).
# You can have multiple passdbs and userdbs. This is useful if you want to
# allow both system users (/etc/passwd) and virtual users to login without
# duplicating the system users into virtual database.
#
# <doc/wiki/PasswordDatabase.txt>
#
# User database specifies where mails are located and what user/group IDs
# own them. For single-UID configuration use « static » userdb.
#
# <doc/wiki/UserDatabase.txt>
#!include auth-deny.conf.ext
#!include auth-master.conf.ext
#!include auth-system.conf.ext
# Use the SQL database configuration for authentication rather than
# any of these others.
!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# Location for users’ mailboxes. The default is empty, which means that Dovecot
# tries to find the mailboxes automatically. This won’t work if the user
# doesn’t yet have any mail, so you should explicitly tell Dovecot the full
# location.
#
# If you’re using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn’t enough. You’ll also need to tell Dovecot where the other mailboxes are
# kept. This is called the « root mail directory », and it must be the first
# path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
# %u – username
# %n – user part in user@domain, same as %u if there’s no domain
# %d – domain part in user@domain, empty if there’s no domain
# %h – home directory
#
# See doc/wiki/Variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
mail_location = maildir:/var/vmail/%d/%n
|
1
2
3
4
5
|
# System user and group used to access mails. If you use multiple, userdb
# can override these by returning uid or gid fields. You can use either numbers
# or names. <doc/wiki/UserIds.txt>
mail_uid = vmail
mail_gid = mail
|
1
2
3
4
5
6
7
8
|
# Valid UID range for users, defaults to 500 and above. This is mostly
# to make sure that users can’t log in as daemons or other system users.
# Note that denying root logins is hardcoded to dovecot binary and can’t
# be done even if first_valid_uid is set to 0.
#
# Use the vmail user uid here.
first_valid_uid = 150
last_valid_uid = 150
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
ssl = yes
# PEM encoded X.509 SSL/TLS certificate and private key. They’re opened before
# dropping root privileges, so keep the key file unreadable by anyone but
# root. Included doc/mkcert.sh can be used to easily generate self-signed
# certificate, just make sure to update the domains in dovecot-openssl.cnf
#
# The generated snakeoil certificate:
#ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
#ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
# Let’s Encrypt certificate:
ssl_cert = </etc/letsencrypt/live/mail.example.com/cert.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
# If key file is password protected, give the password here. Alternatively
# give it when starting dovecot with -p parameter. Since this file is often
# world-readable, you may want to place this setting instead to a different
# root owned 0600 file by using ssl_key_password = <path.
#ssl_key_password =
# PEM encoded trusted certificate authority. Set this only if you intend to use
# ssl_verify_client_cert=yes. The file should contain the CA certificate(s)
# followed by the matching CRL(s). (e.g. ssl_ca = </etc/ssl/certs/ca.pem)
ssl_ca = </etc/letsencrypt/live/mail.example.com/chain.pem
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# DH parameters length to use. In light of Logjam, has to be 2048 or more.
ssl_dh_parameters_length = 2048
# SSL protocols to use. Don’t use the no-longer secure protocols.
ssl_protocols = !SSLv2 !SSLv3
# SSL ciphers to use. See:
ssl_cipher_list = ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
# Prefer the server’s order of ciphers over client’s.
ssl_prefer_server_ciphers = yes
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
service auth {
# auth_socket_path points to this userdb socket by default. It’s typically
# used by dovecot-lda, doveadm, possibly imap process, etc. Users that have
# full permissions to this socket are able to get a list of all usernames and
# get the results of everyone’s userdb lookups.
#
# The default 0666 mode allows anyone to connect to the socket, but the
# userdb lookups will succeed only if the userdb returns an « uid » field that
# matches the caller process’s UID. Also if caller’s uid or gid matches the
# socket’s uid or gid the lookup succeeds. Anything else causes a failure.
#
# To give the caller full permissions to lookup all users, set the mode to
# something else than 0666 and Dovecot lets the kernel enforce the
# permissions (e.g. 0777 allows everyone full permissions).
unix_listener auth-userdb {
mode = 0666
user = vmail
group = mail
}
unix_listener /var/spool/postfix/private/auth {
mode = 0666
# Assuming the default Postfix user and group
user = postfix
group = postfix
}
|
1
2
3
|
# Address to use when sending rejection mails.
# Default is postmaster@<your domain>.
postmaster_address = postmaster@example.com
|
1
2
|
chown-R vmail:dovecot/etc/dovecot
chmod-R o-rwx/etc/dovecot
|
1
2
|
adduser clamav amavis
adduser amavis clamav
|
1
2
3
|
# Needed to allow things to work with Amavis, when both amavis and clamav
# users are added to one another’s groups.
AllowSupplementaryGroups true
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
use strict;
# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.
#
# Default antivirus checking mode
# Please note, that anti-virus checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:
@bypass_virus_checks_maps = (
\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
#
# Default SPAM checking mode
# Please note, that anti-spam checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
1; # ensure a defined return
|
1
2
|
# Change to one to enable spamd
ENABLED=1
|
1
2
3
4
|
# Cronjob
# Set to anything but 0 to enable the cron job to automatically update
# spamassassin’s rules on a nightly basis
CRON=1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
use strict;
#
# Place your configuration directives here. They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#
# Three concurrent processes. This should fit into the RAM available on an
# AWS micro instance. This has to match the number of processes specified
# for Amavis in /etc/postfix/master.cf.
$max_servers = 3;
# Add spam info headers if at or above that level – this ensures they
# are always added.
$sa_tag_level_deflt = -9999;
# Check the database to see if mail is for local delivery, and thus
# should be spam checked.
@lookup_sql_dsn = (
[‘DBI:mysql:database=mail;host=127.0.0.1;port=3306’,
‘mail’,
‘mailpassword’]);
$sql_select_policy = ‘SELECT domain from domain WHERE CONCAT(« @ »,domain) IN (%k)’;
# Uncomment to bump up the log level when testing.
# $log_level = 2;
#———— Do not modify anything below this line ————-
1; # ensure a defined return
|
1
|
freshclam
|
1
2
3
|
service clamav-daemon restart
service amavis restart
service spamassassin restart
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT goto FROM alias,alias_domain
WHERE alias_domain.alias_domain = ‘%d’
AND alias.address=concat(‘%u’, ‘@’, alias_domain.target_domain)
AND alias.active = 1
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
table = alias
select_field = goto
where_field = address
additional_conditions = and active = ‘1’
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = ‘0’ and active = ‘1’
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT maildir FROM mailbox, alias_domain
WHERE alias_domain.alias_domain = ‘%d’
AND mailbox.username=concat(‘%u’, ‘@’, alias_domain.target_domain )
AND mailbox.active = 1
|
1
2
3
4
5
6
7
8
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
table = mailbox
select_field = CONCAT(domain, ‘/’, local_part)
where_field = username
additional_conditions = and active = ‘1’
|
1
2
3
4
5
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT goto FROM alias WHERE address=’%s’
|
1
2
3
4
5
6
|
/^Received:/ IGNORE
/^User-Agent:/ IGNORE
/^X-Mailer:/ IGNORE
/^X-Originating-IP:/ IGNORE
/^x-cr-[a-z]*:/ IGNORE
/^Thread-Index:/ IGNORE
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# The first text sent to a connecting process.
smtpd_banner = $myhostname ESMTP $mail_name
biff = no
# appending .domain is the MUA’s job.
append_dot_mydomain = no
readme_directory = no
# ———————————
# SASL parameters
# ———————————
# Use Dovecot to authenticate.
smtpd_sasl_type = dovecot
# Referring to /var/spool/postfix/private/auth
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
smtpd_sasl_authenticated_header = yes
# ———————————
# TLS parameters
# ———————————
# The default snakeoil certificate.
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
# Let’s Encrypt certificate.
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.example.com/cert.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_tls_CAfile=/etc/letsencrypt/live/mail.example.com/chain.pem
# Ensure we’re not using no-longer-secure protocols.
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# Note that forcing use of TLS is going to cause breakage – most mail servers
# don’t offer it and so delivery will fail, both incoming and outgoing. This is
# unfortunate given what various governmental agencies are up to these days.
#
# Enable (but don’t force) all incoming smtp connections to use TLS.
smtpd_tls_security_level = may
# Enable (but don’t force) all outgoing smtp connections to use TLS.
smtp_tls_security_level = may
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
# ———————————
# TLS Updates relating to Logjam SSL attacks.
# ———————————
smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC4, MD5, PSK, aECDH, EDH-DSS-DES-CBC3-SHA, EDH-RSA-DES-CDC3-SHA, KRB5-DE5, CBC3-SHA
smtpd_tls_dh1024_param_file = /etc/ssl/private/dhparams.pem
# ———————————
# SMTPD parameters
# ———————————
# Uncomment the next line to generate « delayed mail » warnings
#delay_warning_time = 4h
# will it be a permanent error or temporary
unknown_local_recipient_reject_code = 450
# how long to keep message on queue before return as failed.
maximal_queue_lifetime = 7d
# max and min time in seconds between retries if connection failed
minimal_backoff_time = 1000s
maximal_backoff_time = 8000s
# how long to wait when servers connect before receiving rest of data
smtp_helo_timeout = 60s
# how many address can be used in one message.
# effective stopper to mass spammers, accidental copy in whole address list
# but may restrict intentional mail shots.
smtpd_recipient_limit = 16
# how many error before back off.
smtpd_soft_error_limit = 3
# how many max errors before blocking it.
smtpd_hard_error_limit = 12
# This next set are important for determining who can send mail and relay mail
# to other servers. It is very important to get this right – accidentally producing
# an open relay that allows unauthenticated sending of mail is a Very Bad Thing.
#
# You are encouraged to read up on what exactly each of these options accomplish.
# Requirements for the HELO statement
smtpd_helo_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_hostname, reject_invalid_hostname, permit
# Requirements for the sender details. Note that the order matters.
smtpd_sender_restrictions = permit_mynetworks, reject_authenticated_sender_login_mismatch, permit_sasl_authenticated, warn_if_reject reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit
# Requirements for the connecting server
smtpd_client_restrictions = reject_rbl_client sbl.spamhaus.org, reject_rbl_client blackholes.easynet.nl
# Requirement for the recipient address. Note that the entry for
# « check_policy_service inet:127.0.0.1:10023 » enables Postgrey.
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service unix:private/policy-spf, check_policy_service inet:127.0.0.1:10023, permit
smtpd_data_restrictions = reject_unauth_pipelining
# This is a new option as of Postfix 2.10, and is required in addition to
# smtpd_recipient_restrictions for things to work properly in this setup.
smtpd_relay_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service unix:private/policy-spf, check_policy_service inet:127.0.0.1:10023, permit
# require proper helo at connections
smtpd_helo_required = yes
# waste spammers time before rejecting them
smtpd_delay_reject = yes
disable_vrfy_command = yes
# ———————————
# General host and delivery info
# ———————————-
myhostname = mail.example.com
myorigin = /etc/hostname
# Some people see issues when setting mydestination explicitly to the server
# subdomain, while leaving it empty generally doesn’t hurt. So it is left empty here.
# mydestination = mail.example.com, localhost
mydestination =
# If you have a separate web server that sends outgoing mail through this
# mailserver, you may want to add its IP address to the space-delimited list in
# mynetworks, e.g. as 10.10.10.10/32.
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
mynetworks_style = host
# This specifies where the virtual mailbox folders will be located.
virtual_mailbox_base = /var/vmail
# This is for the mailbox location for each user. The domainaliases
# map allows us to make use of Postfix Admin’s domain alias feature.
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/mysql_virtual_mailbox_domainaliases_maps.cf
# and their user id
virtual_uid_maps = static:150
# and group id
virtual_gid_maps = static:8
# This is for aliases. The domainaliases map allows us to make
# use of Postfix Admin’s domain alias feature.
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/mysql_virtual_alias_domainaliases_maps.cf
# This is for domain lookups.
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
# Used in conjunction with reject_authenticated_sender_login_mismatch to
# verify that the sender is sending with their own address, or with one
# of the aliases mapped to that address.
smtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_login_maps.cf
# ———————————
# Integration with other packages
# —————————————
# Tell postfix to hand off mail to the definition for dovecot in master.cf
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
# Use amavis for virus and spam scanning
content_filter = amavis:[127.0.0.1]:10024
# Settings for checking SPF to cut down spam.
policy-spf_time_limit = 3600s
# ———————————
# Header manipulation
# ————————————–
# Getting rid of unwanted headers. See: https://posluns.com/guides/header-removal/
header_checks = regexp:/etc/postfix/header_checks
# getting rid of x-original-to
enable_original_recipient = no
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: « man 5 master » or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute « postfix reload » after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (no) (never) (100)
# ==========================================================================
smtp inet n – y – – smtpd
#smtp inet n – y – 1 postscreen
#smtpd pass – – y – – smtpd
#dnsblog unix – – y – 0 dnsblog
#tlsproxy unix – – y – 0 tlsproxy
# SMTP with TLS on port 587. Currently commented.
#submission inet n – y – – smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_enforce_tls=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject
# -o smtpd_sasl_tls_security_options=noanonymous
# SMTP over SSL on port 465.
smtps inet n – y – – smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject
-o smtpd_sasl_security_options=noanonymous,noplaintext
-o smtpd_sasl_tls_security_options=noanonymous
#628 inet n – y – – qmqpd
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
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
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
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix – n n – – pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing « lmtp » master.cfentry.
#
# Specify in cyrus.conf:
# lmtp cmd= »lmtpd -a » listen= »localhost:lmtp » proto=tcp4
#
# Specify in main.cfone or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix – n n – – pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix – n n – – pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix – n n – – pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender – $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
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}
# The next two entries integrate with Amavis for anti-virus/spam checks.
amavis unix – – y – 3 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
127.0.0.1:10025 inet n – y – – smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters
# Integration with Dovecot – hand mail over to it for local delivery, and
# run the process under the vmail user and mail group.
dovecot unix – n n – – pipe
flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/dovecot-lda -d $(recipient)
# Integration with the SPF check package.
policy-spf unix – n n – – spawn
user=nobody argv=/usr/bin/policyd-spf
|
1
2
3
4
5
|
service postfix restart
service spamassassin restart
service clamav-daemon restart
service amavis restart
service dovecot restart
|
1
|
apt-getinstall–assume-yesmonit
|
1
2
3
4
5
6
7
|
check process amavisd with pidfile /var/run/amavis/amavisd.pid
every 5 cycles
group mail
start program = « /usr/sbin/service amavis start »
stop program = « /usr/sbin/service amavis stop »
if failed port 10024 protocol smtp then restart
if 5 restarts within 25 cycles then timeout
|
1
2
3
4
5
6
7
8
9
10
11
|
check process apache2 with pidfile /var/run/apache2/apache2.pid
group www
start program = « /usr/sbin/service apache2 start »
stop program = « /usr/sbin/service apache2 stop »
if failed host localhost port 80 protocol http
with timeout 10 seconds
then restart
if failed host localhost port 443 type tcpssl protocol http
with timeout 10 seconds
then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
6
7
8
9
10
|
check process dovecot with pidfile /var/run/dovecot/master.pid
group mail
start program = « /usr/sbin/service dovecot start »
stop program = « /usr/sbin/service dovecot stop »
group mail
# We’d like to use this line, but see:
#if failed port 993 type tcpssl sslauto protocol imap for 5 cycles then restart
if failed port 993 for 5 cycles then restart
if 5 restarts within 25 cycles then timeout
|
1
2
3
4
5
6
|
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
start program = « /usr/sbin/service mysql start »
stop program = « /usr/sbin/service mysql stop »
if failed host localhost port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
6
|
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = « /usr/sbin/service postfix start »
stop program = « /usr/sbin/service postfix stop »
if failed port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
|
check process spamassassin with pidfile /var/run/spamd.pid
group mail
start program = « /usr/sbin/service spamassassin start »
stop program = « /usr/sbin/service spamassassin stop »
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
|
check process sshd with pidfile /var/run/sshd.pid
start program « /usr/sbin/service ssh start »
stop program « /usr/sbin/service ssh stop »
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
|
1
2
3
4
5
6
7
8
9
10
11
12
|
## Monit has an embedded HTTP interface which can be used to view status of
## services monitored and manage services from a web interface. The HTTP
## interface is also required if you want to issue Monit commands from the
## command line, such as ‘monit status’ or ‘monit restart service’ The reason
## for this is that the Monit client uses the HTTP interface to send these
## commands to a running Monit daemon. See the Monit Wiki if you want to
## enable SSL for the HTTP interface.
#
set httpd port 2812 and
use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
# allow admin:monit # require user ‘admin’ with password ‘monit’
|
1
|
service monit restart
|
1
|
monit status
|
1
2
|
# monit monitor <name>, e.g.:
monit monitor mysqld
|
1
2
3
4
5
6
7
8
|
apt-getinstall–assume-yes\
roundcube \
roundcube-plugins \
php7.2-mail \
php-mime-type\
php-mail-mime \
php7.2-intl \
php7.2-zip
|
1
|
pearinstallNet_IDNA2-0.2.0 Mail_mimeDecode-1.5.6
|
1
|
service apache2 restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// The mail host chosen to perform the log-in.
// Leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// Supported replacement variables:
// %n – hostname ($_SERVER[‘SERVER_NAME’])
// %t – hostname without the first part
// %d – domain (http hostname $_SERVER[‘HTTP_HOST’] without the first part)
// %s – domain name after the ‘@’ from e-mail address provided at login screen
// For example %n = mail.domain.tld, %t = domain.tld
// WARNING: After hostname change update of mail_host column in users table is
// required to match old user data records with the new host.
$config[‘default_host’] =’localhost’;
// SMTP server host (for sending mails).
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// If left blank, the PHP mail() function is used
// Supported replacement variables:
// %h – user’s IMAP hostname
// %n – hostname ($_SERVER[‘SERVER_NAME’])
// %t – hostname without the first part
// %d – domain (http hostname $_SERVER[‘HTTP_HOST’] without the first part)
// %z – IMAP domain (IMAP hostname without the first part)
// For example %n = mail.domain.tld, %t = domain.tld
$config[‘smtp_server’] =’localhost’;
|
1
2
3
4
5
6
7
8
9
10
|
// enforce connections over https
// with this option enabled, all non-secure connections will be redirected.
// set the port for the ssl connection as value of this option if it differs from the default 443
$config[‘force_https’] = true;
// Type of IMAP indexes cache. Supported values: ‘db’, ‘apc’ and ‘memcache’.
$config[‘imap_cache’] =’db’;
// Backend to use for session storage. Can either be ‘db’ (default) or ‘memcache’
$config[‘session_storage’] =’db’;
|
1
2
3
4
5
|
// this key is used to encrypt the users imap password which is stored
// in the session record (and the client cookie if remember password is enabled).
// please provide a string of exactly 24 chars.
// YOUR KEY MUST BE DIFFERENT THAN THE SAMPLE VALUE FOR SECURITY REASONS
$config[‘des_key’] =’enter a unique value here’;
|
1
|
ln-s/var/lib/roundcube/var/www/html/roundcube
|
1
|
mv/var/www/html/index.html/var/www/html/index.bak.html
|
1
2
3
4
5
6
7
8
|
RewriteEngine On
# Redirect all HTTP traffic to HTTPS.
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# Send / to /roundcube.
RewriteRule ^/?$ /roundcube [L]
|
1
|
« v=spf1 a mx -all »
|
1
|
dig google.comtxt
|
1
|
apt-getinstall–assume-yesopendkim opendkim-tools
|
1
2
3
|
1
|
Socket inet:8891@localhost
|
1
|
SOCKET=inet:8891@localhost
|
1
2
3
4
5
6
7
|
# ————————————–
# DKIM
# ————————————–
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
|
1
|
op/endkim-genkey -t -s dkim -d example.com
|
1
2
3
|
mvdkim.private/etc/postfix/dkim.key
chmod660/etc/postfix/dkim.key
chownroot:opendkim/etc/postfix/dkim.key
|
1
2
|
service opendkim start
service postfix restart
|
1
2
|
dkim._domainkey IN TXT ( « v=DKIM1; k=rsa; t=y; «
« p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9rulKo58JIb5h+3MMEnYhlnbuVgRoA4w68R/X7qA2Lfv3RpdrrUb+r7KxemIo6PUIOm6uZ5OymhBgpJ0LAWBHBSJjnFmDXNajSgxMOcvkpgmVCW1/k1kxK864WVVSyFVQPyUImqklY+ws4u+mog3PSbuq2J8NFAnvSwzMg3vT1QIDAQAB » ; —– DKIM key mail for example.com
|
1
|
« v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9rulKo58JIb5h+3MMEnYhlnbuVgRoA4w68R/X7qA2Lfv3RpdrrUb+r7KxemIo6PUIOm6uZ5OymhBgpJ0LAWBHBSJjnFmDXNajSgxMOcvkpgmVCW1/k1kxK864WVVSyFVQPyUImqklY+ws4u+mog3PSbuq2J8NFAnvSwzMg3vT1QIDAQAB »
|
1
|
dig dkim._domainkey.twitter.comtxt
|
1
2
3
4
5
|
check process opendkim with pidfile /var/run/opendkim/opendkim.pid
group mail
start program = « /etc/init.d/opendkim start »
stop program = « /etc/init.d/opendkim stop »
if 5 restarts within 5 cycles then timeout
|
1
|
service monit restart
|
1
2
3
4
|
Domain *
KeyFile /etc/postfix/dkim.key
Selector dkim
SOCKET inet:8891@localhost
|
1
2
|
cp/etc/postgrey/whitelist_clients/etc/postfix/postgrey_whitelist_clients
cp/etc/postgrey/whitelist_recipients/etc/postfix/postgrey_whitelist_recipients
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# postgrey startup options, created for Debian
# you may want to set
# –delay=N how long to greylist, seconds (default: 300)
# –max-age=N delete old entries after N days (default: 35)
# see also the postgrey(8) manpage
POSTGREY_OPTS= »–inet=10023″
POSTGREY_OPTS= »$POSTGREY_OPTS –whitelist-clients=/etc/postgrey/whitelist_clients »
POSTGREY_OPTS= »$POSTGREY_OPTS –whitelist-recipients=/etc/postgrey/whitelist_recipients »
# the –greylist-text commandline argument can not be easily passed through
# POSTGREY_OPTS when it contains spaces. So, insert your text here:
#POSTGREY_TEXT= »Your customized rejection message here »
|
1
2
3
4
5
|
user = mail
password = mailpassword
hosts = 127.0.0.1
dbname = mail
query = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ‘1’ AND active = ‘1’
|
1
2
3
|
# This is a backup MX server, and this line tells Postfix
# where to send the mail.
relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf
|
1
2
3
|
1
2
3
4
5
|
// Quota
// When you want to enforce quota for your mailbox users set this to ‘YES’.
$CONF[‘quota’] =’YES’;
// You can either use ‘1024000’ or ‘1048576’
$CONF[‘quota_multiplier’] =’1024000′;
|
1
2
3
4
5
6
7
8
9
10
11
12
|
// Optional:
// Show used quotas from Dovecot dictionary backend in virtual
// mailbox listing.
// See: DOCUMENTATION/DOVECOT.txt
//
$CONF[‘used_quotas’] =’YES’;
// if you use dovecot >= 1.2, set this to yes.
// Note about dovecot config: table « quota » is for 1.0 & 1.1,
// table « quota2 » is for dovecot 1.2 and newer
$CONF[‘new_quota_table’] =’YES’;
|
1
2
3
4
5
6
7
8
9
10
|
# Replace 111.111.111.111/32 with your desired list of client IP address
# ranges which will bypass checks.
@mynetworks = qw( 127.0.0.0/8 [::1] 111.111.111.111/32 );
# Rules for clients defined in @mynetworks
$policy_bank{‘MYNETS’} = {
bypass_spam_checks_maps => [1], # don’t spam-check internal mail
bypass_banned_checks_maps => [1], # don’t banned-check internal mail
bypass_header_checks_maps => [1], # don’t header-check internal mail
};
|