Atenção:
Para o servidor de e-mail funcionar corretamente é necessário endereço IP público com reverso apontando para o endereço seu servidor. O(s) domínio(s) deve(m) estar registrado(s) nos órgãos competentes.
Após uma instalação simples do Centos 7 (mínima):
Vamos instalar as Ferramentas de desenvolvimento, pois será necessário compilarmos algumas aplicações posteriormente.
yum -y install "Ferramentas de Desenvolvimento"
yum -y install wget whois nc vim gpm dialog logwatch telnet nmap mutt
yum -y install epel-release
yum -y update
yum -y install perl-MailTools perl-MIME-EncWords perl-Email-Valid perl-Test-Pod dovecot dovecot-mysql dovecot-pigeonhole perl-Mail-Sender perl-Log-Log4perl imapsync offlineimap amavisd-new clamav perl-Razor-Agent mariadb-server opendkim vim crypto-utils mod_ssl php php-mysql php-fpm clamav-update php-imap mailx lrzip lzop lz4 arj unzoo cabextract p7zip unzip unrar fail2ban php-mcrypt
Presumo que este servidor também será usado para responder pelo serviço de DNS.yum -y install bind bind-devel bind-utils
systemctl stop rpcbind
systemctl disable rpcbind
Configure o seu hostname server.hostnamectl set-hostname mail.seudominio.com.br
echo "192.168.30.2 mail.seudominio.com.br" >> /etc/hosts
Até aqui o servidor já poderá enviar e-mails dos usuários registrados no servidor através de um único domínio.
Lembre-se que o serviço de dns já deve estar configurado, com reverso apontando para essa máquina. Mas vamos continuar, pois queremos que esse servidor de e-mail possa ser usado para mais de um domínio.
PS: No Centos 7 o MySQL-Server foi substituído pelo Mariadb.
Habilite inicie o serviço Mariadb systemctl enable mariadb.service
systemctl start mariadb.service
mysql_secure_installation
Configurando Clam Antivirus:vim /etc/sysconfig/freshclam
Comente ou remova esta linha# FRESHCLAM_DELAY=disabled-warn # REMOVE ME
Editando clamav configvim /etc/freshclam.conf
Comente a linha:# Example
Faça um update do database.freshclam
Habilitar o serviço do spamassasinsystemctl start spamassassin.service
systemctl status spamassassin.service
systemctl enable spamassassin.service
Update spamassasinsa-update
Integrando spamassasin e clamav com o amavisd.yum -y install clamav clamav-devel clamav-server clamd
cp /usr/share/doc/clamav-server-0.99.2/clamd.sysconfig /etc/sysconfig/clamd.amavisd
vim /etc/sysconfig/clamd.amavisd
CLAMD_CONFIGFILE=/etc/clamd.d/amavisd.conf
CLAMD_SOCKET=/var/run/clamd.amavisd/clamd.sock
#CLAMD_OPTIONS=
vi /etc/tmpfiles.d/clamd.amavisd.conf
D /var/run/clamd.amavisd 0755 amavis amavis -
vi /usr/lib/systemd/system/[email protected]
[Unit]
Description = clamd scanner (%i) daemon
After = syslog.target nss-lookup.target network.target
[Service]
Type = simple
ExecStart = /usr/sbin/clamd -c /etc/clamd.d/%i.conf --foreground=yes
Restart = on-failure
PrivateTmp = true
[Install]
WantedBy=multi-user.target
systemctl start clamd@amavisd
systemctl enable clamd@amavisd
systemctl status clamd@amavisd
vi /etc/amavisd/amavisd.conf
$max_servers = <number>
linha 20 $mydomain$mydomain = ‘ceae.info’;
linha 152 hostname$myhostname= ‘mail.ceae.info’;
systemctl start amavisd.service
# ServerAdmin root@localhost
## AllowOverride None
AllowOverride All
;cgi.fix_pathinfo=1
cgi.fix_pathinfo=0
;date.timezone =
date.timezone = America/Sao_Paulo
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.0/postfixadmin-3.0.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fpostfixadmin%2Ffiles%2Fpostfixadmin%2Fpostfixadmin-3.0%2F&ts=1479731076&use_mirror=netix
postfixadmin-3.0.tar.gz
tar -zxvf postfixadmin-3.0.tar.gz -C /var/www/html/
cd /var/www/html/
chown -R root.apache postfixadmin-3.0/
ln -s postfixadmin-3.0/ postfixadmin
mysql -u root -p
MariaDB [(none)]> create database postfix;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> GRANT all on postfix.* to 'postfix'@'localhost' identified by 'yourPASSword';
Query OK, 0 rows affected (0.00 sec)
$CONF[‘configured’] = true;
$CONF[‘setup_password’] = ‘YOUR-STRONG-PASSWORD’;
$CONF[‘database_type’] = ‘mysqli’;
$CONF[‘database_host’] = ‘localhost’;
$CONF[‘database_user’] = ‘postfix’;
$CONF[‘database_password’] = ‘yourPASSword’;
$CONF[‘database_name’] = ‘postfix’;$CONF[‘show_password’] = ‘YES’;$CONF[‘page_size’] = ’30’;$CONF[‘default_aliases’] = array (
‘abuse’ => ‘[email protected]’,
‘hostmaster’ => ‘[email protected]’,
‘postmaster’ => ‘[email protected]’,
‘webmaster’ => ‘[email protected]’
);$CONF[‘domain_path’] = ‘NO’;
$CONF[‘domain_in_mailbox’] = ‘YES’;
$CONF[‘maildir_name_hook’] = ‘NO’;$CONF[‘transport’] = ‘YES’;$CONF[‘vacation’] = ‘YES’;$CONF[‘vacation_domain’] = ‘autoreply.ceae.info’;$CONF[‘vacation_control’] =’YES’;
$CONF
[
'emailcheck_resolve_domain'
]=
'NO'
;
# The mysqld.sock socket may be in different locations in different systems
driver = mysql
##
connect = host=localhost dbname=postfix user=postfix password=yourpassword
#
# Default password scheme.
# depends on your $CONF['encrypt'] setting:
# md5crypt -> MD5-CRYPT
# md5 -> PLAIN-MD5
# cleartext -> PLAIN
default_pass_scheme = MD5-CRYPT
# Query to retrieve password. user can be used to retrieve username in other
# # formats also.
password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1'
# Query to retrieve user information.
## user_query = SELECT maildir, 1001 AS uid, 1001 AS gid FROM mailbox WHERE username = '%u' AND active='1'
user_query = SELECT CONCAT('/var/spool/vmail/', domain,'/', maildir) AS
home, CONCAT('maildir:/var/spool/vmail/',domain,'/', maildir) AS mail,
5000 AS uid, 12 AS gid, concat('dict:storage=',CAST(ROUND(quota / 1024)
AS CHAR), '::proxy::quota') AS quota, CONCAT('*:storage=',CAST(quota AS
CHAR), 'B') AS quota_rule FROM mailbox WHERE username = '%u' AND active =
'1'
connect = host=localhost dbname=postfix user=postfix password=yourpassword
map {
pattern = priv/quota/storage
table = quota2
username_field = username
value_field = bytes
}
map {
pattern = priv/quota/messages
table = quota2
username_field = username
value_field = messages
}
protocols = imap pop3
#login_greeting = Dovecot ready.
login_greeting = Server OK.
shutdown_clients = yes
auth_verbose_passwords = plain
#auth_debug_passwords = no
auth_debug_passwords = yes
systemctl restart dovecot.service
useradd -r -u 5000 -g mail -d /var/spool/vmail -s /sbin/nologin -c "Virtual mailbox" vmail
mkdir /var/spool/vmail
/var/log/dovecot.log {
missingok
notifempty
delaycompress
sharedscripts
postrotate
/bin/kill -USR1 `cat /var/run/dovecot/master.pid 2>/dev/null` 2> /dev/null || true
endscript
}
disable_plaintext_auth = yes
auth_mechanisms = plain login cram-md5
#!include auth-system.conf.ext
!include auth-sql.conf.ext
ssl_protocols = !SSLv2 !SSLv3
ssl_cipher_list = EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4
ssl_prefer_server_ciphers = yes
service imap-login {
inet_listener imap {
port = 143
}
inet_listener imaps {
port = 993
ssl = yes
}
service pop3-login {
inet_listener pop3 {
port = 110
}
inet_listener pop3s {
port = 995
ssl = yes
}
}
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = vmail
group = mail
}
protocol lda {
# Space separated list of plugins to load (default is global mail_plugins).
#mail_plugins = $mail_plugins
mail_plugins = $mail_plugins sieve
}