Installing Postfix (MTA)
Environment: Debian 8.6 x64
Excerpt: http://www.postfix.org/postconf.5.html
Mail Transfer Agent (MTA) that can be used to route and deliver email on a Linux system.
root@echidna:~# apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
Select Internet Site
root@echidna:~# apt-get install postfix -y && postfix stop
Adding group `postfix' (GID 115) ...
Done.
Adding system user `postfix' (UID 108) ...
Adding new user `postfix' (UID 108) with group `postfix' ...
Not creating home directory `/var/spool/postfix'.
Creating /etc/postfix/dynamicmaps.cf
Adding tcp map entry to /etc/postfix/dynamicmaps.cf
Adding sqlite map entry to /etc/postfix/dynamicmaps.cf
Adding group `postdrop' (GID 116) ...
Done.
setting myhostname: echidna
setting alias maps
setting alias database
changing /etc/mailname to zuhdi.xyz
setting myorigin
setting destinations: zuhdi.xyz, echidna, localhost.localdomain, localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_command
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
WARNING: /etc/aliases exists, but does not have a root alias.
Postfix is now set up with a default configuration. If you need to make
changes, edit
/etc/postfix/main.cf (and others) as needed. To view Postfix configuration
values, see postconf(1).
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
Running newaliases
If you want to skip the default, ssl-cert-snakeoil.pem
root@echidna:~# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/mail.key -out /etc/ssl/certs/mailcert.pem
Generating a 2048 bit RSA private key
.....+++
.......................+++
writing new private key to '/etc/ssl/private/mail.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:MY
State or Province Name (full name) [Some-State]:Selangor
Locality Name (eg, city) []:Seri Kembangan
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Lestari
Organizational Unit Name (eg, section) []:DevOps
Common Name (e.g. server FQDN or YOUR name) []:mail.zuhdi.xyz
Email Address []:root@zuhdi.xyz
main.cf
root@echidna:~# cp /etc/postfix/main.cf /etc/postfix/main.cf.original
root@echidna:~# nano /etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
#delay_warning_time = 4h
readme_directory = no
smtpd_tls_cert_file=/etc/ssl/certs/mailcert.pem
smtpd_tls_key_file=/etc/ssl/private/mail.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = echidna
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = zuhdi.xyz, echidna, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
Create user matt
and liyana
root@echidna:~# adduser matt
Adding user `matt' ...
Adding new group `matt' (1000) ...
Adding new user `matt' (1000) with group `matt' ...
Creating home directory `/home/matt' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for matt
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
root@echidna:~# newaliases
Run it
root@echidna:~# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
root@echidna:~# systemctl restart postfix
Test it
root@echidna:~# apt-get install mailutils -y
root@echidna:~# mail -s 'this is the subject' matt@zuhdi.xyz <<< 'Hello Matt, this is the message!'
root@echidna:~# su matt
matt@echidna:/root$ mailx
"/var/mail/matt": 1 message 1 new
>N 1 root Sun Nov 13 12:40 13/427 this is the subject
?
Return-Path: <root@echidna>
X-Original-To: matt@zuhdi.xyz
Delivered-To: matt@zuhdi.xyz
Received: by echidna (Postfix, from userid 0)
id 6980E1FED0; Sun, 13 Nov 2016 12:40:30 +0000 (UTC)
Subject: this is the subject
To: <matt@zuhdi.xyz>
X-Mailer: mail (GNU Mailutils 2.99.98)
Message-Id: <20161113124030.6980E1FED0@echidna>
Date: Sun, 13 Nov 2016 12:40:30 +0000 (UTC)
From: root@echidna (root)
Hello Matt, this is the message!
? exit
Let’s stir things up virtual_alias_maps
replace alias_maps
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
#delay_warning_time = 4h
readme_directory = no
smtpd_tls_cert_file=/etc/ssl/certs/mailcert.pem
smtpd_tls_key_file=/etc/ssl/private/mail.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = echidna
#alias_maps = hash:/etc/aliases
virtual_alias_maps = hash:/etc/postfix/virtual
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = zuhdi.xyz, echidna, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
root@echidna:~# nano /etc/postfix/virtual
admin@zuhdi.xyz root
matt@zuhdi.xyz matt
support@zuhdi.xyz liyana,matt
root@echidna:~# postmap /etc/postfix/virtual
root@echidna:~# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
root@echidna:~# systemctl restart postfix
Version
root@echidna:~# postconf -d | grep "^mail_version"
mail_version = 2.11.3