Ubuntu 16: Postfix & Dovecot

Title might be misleading > also excellent instructions for setting up Postfix and Dovecot


Open lightsail ports
Custom TCP 25 
Custom TCP 110 
Custom TCP 143 
Custom TCP 993 
Custom TCP 995
sudo netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      4786/mysqld     
tcp        0      0   *               LISTEN      5971/dovecot    
tcp        0      0   *               LISTEN      5971/dovecot    
tcp        0      0    *               LISTEN      926/nginx -g daemon
tcp        0      0    *               LISTEN      1194/sshd       
tcp        0      0    *               LISTEN      907/master      
tcp        0      0   *               LISTEN      926/nginx -g daemon
tcp6       0      0 :::110                  :::*                    LISTEN      5971/dovecot    
tcp6       0      0 :::143                  :::*                    LISTEN      5971/dovecot    
tcp6       0      0 :::80                   :::*                    LISTEN      926/nginx -g daemon
tcp6       0      0 :::22                   :::*                    LISTEN      1194/sshd       
tcp6       0      0 :::25                   :::*                    LISTEN      907/master      
tcp6       0      0 :::443                  :::*                    LISTEN      926/nginx -g daemon
DNS settings (Route53) MX 10 PTR A
Local Firewall disabled > lightsail firewall 
sudo ufw status
Status: inactive

sudo service iptables status
● iptables.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
nc -z 110 
Create Mail user
sudo useradd -m -G mail -s /bin/bash/ bernhard
sudo passwd bernhard
sudo deluser --remove-home gabriel
sudo apt install mailutils

su bernhard
Cannot execute /bin/bash/: Not a directory
sudo chsh -s /bin/bash bernhard // > remove /


Postfix setup
sudo apt install postfix
sudo postconf mail_version
sudo service postfix restart
dpkg -L postfix | grep /usr/sbin/

sudo vim /etc/postfix/ 
sudo dpkg-reconfigure postfix
sudo postconf -e 'home_mailbox = Maildir/'
sudo postconf -e 'mydomain ='
sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/'
sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/'
many others, refer to afore mentioned website.

sudo vim /etc/postfix/virtual
root root info
sudo postmap /etc/postfix/virtual
sudo systemctl restart postfix

tail -f /var/log/syslog | grep postfix
vim /var/log/mail.log
list queued messages stuck
sudo mailq

Scenario 1 : Remove particular mail queue id (on running mailq command,you will get mail queue id)
postsuper -d mail_queue_id
Scenario 2: Remove ALL mails from queue
postsuper -d ALL
Scenario 3: Remove only ALL deferred mails which are in queue
postsuper -d ALL deferred


Dovecot setup
sudo apt-get install dovecot-imapd dovecot-pop3d

sudo vim /etc/dovecot/dovecot.conf
Most of the actual configuration gets included below

sudo vim /etc/dovecot/conf.d/10-auth.conf 
disable_plaintext_auth = yes
auth_mechanisms = plain login 

sudo vim /etc/dovecot/conf.d/10-mail.conf 
mail_location = maildir:~/Maildir

sudo vim /etc/dovecot/conf.d/10-ssl.conf 
ssl = required
ssl_cert = </etc/letsencrypt/live/
ssl_key = </etc/letsencrypt/live/

openssl rsa -in /etc/letsencrypt/live/ -check -noout

sudo service dovecot restart

SMTP Banner

sudo vim /etc/postfix/
smtpd_banner = ESMTP $mail_name (Ubuntu)
nc 25                        
220 ESMTP Postfix (Ubuntu) PTR

Test connections:

Leave a Reply

Your email address will not be published. Required fields are marked *