It is a Linux mail server based on the protocols:
- SMTP (Simple Mail Transfer Protocol)
- POP3 (Post Office Protocol)
- IMAP (Internet Message Access Protocol)
Operating system: Debian 9 64bit
No-ip
Thuderbird application
- Packages:
- Postfix
- Spamassassin
- Letsencrypt
- Bsd-mailx
- Procmail
- dovecot-imapd, dovecot-pop3d, dovecot-lmtpd
Mail server with domain: wtmail.hopto.org
Automated script to install an encrypted mail server with a spam tray and also accept the three operating modes:
- Online mode: direct access to emails
- Offline mode: synchronize the tray by taking emails from the mail server
- Disconnected mode: allow users to keep local copies of emails
-
Ask for the dynamic ip domain in No-ip (https://www.noip.com/)
-
Configure the DNS record update in No-ip
-
Download and demonize the noip2 script to start at system boot
wget https://www.noip.com/client/linux/noip-duc-linux.tar.gz tar -xf noip-duc-linux.tar.gz cd noip-2.1.9-1/ make make install cp debian.noip2.sh /etc/init.d/debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc0.d/K01debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc1.d/K01debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc2.d/K01debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc3.d/K01debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc4.d/K01debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc5.d/S01debian.noip2.sh ln -s /etc/init.d/debian.noip2.sh /etc/rc6.d/K01debian.noip2.sh chmod 755 debian.noip2.sh systemctl start postfix systemctl enable postfix
- Set private ip for the mail server
- Open NAT port to receive requests
-
Installl postfix:
apt-get install postfix
-
Install procmail:
apt-get install procmail
-
Configure Postfix in /etc/postfix/main.cf
echo "myhostname = $host_name" >> /etc/postfix/main.cf echo "mydomain = $host_name" >> /etc/postfix/main.cf echo 'myorigin = $mydomain' >> /etc/postfix/main.cf echo 'mydestination= $myhostname, localhost.$mydomain,$mydomain,mail.$mydomain,www.$mydomain' >> /etc/postfix/main.cf echo 'mail_spool_directory = /var/spool/mail' >> /etc/postfix/main.cf echo 'mynetworks = 127.0.0.0/8, 192.168.1.0/24' >> /etc/postfix/main.cf echo 'inet_protocols = ipv4' >> /etc/postfix/main.cf systemctl reload postfix postfix check
-
Implement the SPAM tray using "spamassassin"
apt-get install spamassassin systemctl start spamassassin systemctl enable spamassassin
-
Integrate in postfix and restart it
echo ':0 hbfw' >> /etc/procmailrc echo '| /usr/bin/spamc' >> /etc/procmailrc echo 'mailbox_command = /usr/bin/procmail' >> /etc/postfix/main.cf systemctl restart postfix
-
Secure the SMTP connection through TLS (Generating the certificate and the key using openssl)
cd /etc/postfix openssl genrsa -des3 -out mail.key openssl req -new -key mail.key -out mail.csr cp mail.key mail.key.original openssl rsa -in mail.key.original -out mail_secure.key openssl x509 -req -days 365 -in mail_secure.csr -signkey mail_secure.key -out mail_secure.crt
-
Add the TLS options to the Postfix configuration file /etc/postfix/main.cf
cp mail_secure.crt /etc/postfix/ cp mail_secure.key /etc/postfix/ echo 'smtpd_use_tls = yes' >> /etc/postfix/main.cf echo 'smtpd_tls_cert_file = /etc/postfix/mail_secure.crt' >> /etc/postfix/main.cf echo 'smtpd_tls_key_file = /etc/postfix/mail_secure.key' >> /etc/postfix/main.cf echo 'smtp_tls_security_level = may' >> /etc/postfix/main.cf systemctl restart postfix
-
Encrypt traffic using the free SSL certificate provider (Let's Encrypt)
letsencrypt certonly --standalone -d "$host_name" postconf -e "mtpd_tls_cert_file = /etc/letsencrypt/live/$host_name/fullchain.pem" postconf -e "smtpd_tls_key_file = /etc/letsencrypt/live/$host_name/privkey.pem" systemctl restart postfix
-
Install Dovecot to integrate POP3 and IMAP
apt-get install dovecot-imapd dovecot-pop3d dovecot-lmtpd
-
Configure Dovecot in /etc/dovecot/conf.d/dovecot.conf
systemctl start dovecot systemctl enable dovecot echo "protocols = imap pop3 lmtp" >> /etc/dovecot/dovecot.conf echo "listen = *, ::" >> /etc/dovecot/dovecot.conf echo "userdb {" >> /etc/dovecot/dovecot.conf echo "driver = passwd" >> /etc/dovecot/dovecot.conf echo "}" >> /etc/dovecot/dovecot.conf echo "passdb {" >> /etc/dovecot/dovecot.conf echo "driver = passwd" >> /etc/dovecot/dovecot.conf echo "}" >> /etc/dovecot/dovecot.conf
-
Modify generic Dovecot SSL certificates to Let's Encrypt certificates
echo "mail_location = mbox:~/mail:INBOX=/var/mail/%u" >> /etc/dovecot/conf.d/10-main.conf echo "ssl_cert = </etc/letsencrypt/live/$host_name/fullchain.pem" >> /etc/dovecot/conf.d/10-ssl.conf echo "ssl_key = </etc/letsencrypt/live/$host_name/privkey.pem" >> /etc/dovecot/conf.d/10-ssl.conf echo "ssl = yes" >> /etc/dovecot/conf.d/10-ssl.conf
- Enable MX in No-ip
- Text your email server