Note
Postfix is a mail transfer agent (MTA) responsible for sending out and receiving emails between servers.
Dovecot is a mail delivery agent (MDA) responsible for sending out and receiving emails between a server and its users.
Mail-stack-delivery is a combined package containing both Postfix and Dovecot. It would be easier than to install Postfix and Dovecot separately.
Re-direct to server ports
Set the internet router to re-direct the following connections to server ports:
- SMTP = port 25 (for receiving or sending emails)
- secure SMTP = port 465 (for receiving or sending emails securely)
- IMAP = port 143 (for retrieiving emails)
- secure IMAP = port 993 (for retrieving emails securely)
- POP3 = port 110 (for retrieving emails)
Install both Postfix and Dovecot
Install the combined package:
$ sudo apt-get install mail-stack-delivery
Reconfigure Postfix
Reconfig:
$ sudo dpkg-reconfigure postfix
Use Tab key to change selection.
Select "Internet Site".
Enter the following information:
System mail name: <fully qualified domain name, such as "kctang.com.hk"> Root and postmaster mail recipient: <such as "kctang"> Other destinations to accept mail: <fully qualified domain name, such as "kctang.com.hk">, <server name such as "server1">, localhost.localdomain, localhost Force synchronous updates on mail queue: No Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 Use procmail for local delivery: No Mailbox size limit (bytes): 0 Local address extension character: + Internet protocols to use: all
Activate the changes:
$ sudo systemctl reload postfix or $ sudo service postfix reload
Edit "main.cf" settings:
$ gksudo gedit /etc/postfix/main.cf
Specify:
myhostname = kctang.com.hk # last line changed from server name to fully qualified domain name, # otherwise some servers would not accept e-mails sent without fully qualified domain name, 2/4/2014 message_size_limit = 204800000 # last line added to increase the default 10 times, 5/4/2014 # increased to 20 times, 20/9/2018 maximal_queue_lifetime = 0 # last line added to report unsuccessful delivery immediately instead of after the default of 5 days, 12/4/2018 body_checks = regexp: /etc/postfix/body_checks # last line added to refer to another file to check contents of email bodies, 29/9/2018
Edit "master.cf" settings:
$ gksudo gedit /etc/postfix/master.cf
Specify:
smtp inet n - y - - smtpd smtps inet n - y - - smtpd # last line uncommented -o smtpd_sasl_auth_enable=yes # last line added to enable STARTTLS authentication -o smtpd_client_restrictions=permit_sasl_authenticated,reject # last line added to reject if not authenticated, no space after "," -o smtpd_tls_wrappermode=yes # last line added to force use of TLS -o milter_macro_daemon_name=ORIGINATING # last line added
Create "body_checks" file:
$ gksudo gedit /etc/postfix/body_checks
Specify one or more lines of texts within //:
/unique text contained in email you do not want to receive/ DISCARD
"DISCARD" means delete from the server.
Change Dovecot settings
Edit config file:
$ gksudo gedit /etc/dovecot/conf.d/99-mail-stack-delivery.conf
Specify:
mail_location = maildir:~/Maildir:LAYOUT=fs # LAYOUT=fs added to last line, to use "/" instead of "." to denote sub-folders # IMAP configuration protocol imap { mail_max_userip_connections = 1000 # 10 in last line increased to 1000 imap_client_workarounds = delay-newmail } # POP3 configuration protocol pop3 { mail_max_userip_connections = 50 # 10 in last line increased to 50 pop3_client_workarounds = outlook-no-nuls oe-ns-eoh }
Activate the changes:
$ sudo systmctl reload postfix or $ sudo service postfix reload and $ sudo systemctl restart dovecot or $ sudo service dovecot reload
Verify success
See whether the postfix server is running:
$ telnet localhost 25
should display:
220 kctang.com.hk ESMTP Postfix (Ubuntu)
ehlo localhost
should display the following:
250-kctang.com.hk
250-PIPELINING
250-SIZE 102400000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Ctrl-]
to exit to "telnet >" prompt.
quit
to exit telnet.
Try also:
$ telnet localhost 995
similarly:
$ telnet localhost 465
should display either one:
Connected to localhost
Connected to kctang.com.hk
"Ctrl-]"
to exit to "telnet >" prompt.
quit
to exit telnet.
Specify mail forwarding
Edit "aliases" file:
$ sudo gedit /etc/aliases
Specify:
postmaster: kctang kctcl: kctcl, kctclpop
meaning:
- forwarding e-mails sent to postmaster to kctang, no email will be left at postmaster
- forwarding e-mails sent to kctcl to kctcl (itself) and to kctclpop, i.e. making a copy
Activate setting:
$ sudo newaliases
Revisions
29/9/2018: Add "body_checks" for spam control.
20/9/2018: Increase message_size_limit to 20 times the default.
5/4/2018: Increase message_size_limit to 10 times the default.
12/4/2014: Specify maximal_queue_lifetime to notify unsuccessful delivery immediately.
2/4/2014: Specify fully qualified domain name.