Install Postfix as a relay on an AWS instance

From JMK Wiki
Jump to: navigation, search

Populate the sasl dadatabase.

root@localhost ~ # saslpasswd2 relay-user@dublin-1.eu-west-1.aws.jmk.hu
root@localhost ~ # saslpasswd2 relay-user@nova-1.us-east-1.aws.jmk.hu

Allow postfix to be able to read sasldb.

root@localhost ~ # chown postfix /etc/sasldb2
root@localhost ~ # chmod 600 /etc/sasldb2

Tell postfix to use sasldb.

root@localhost ~ # nano -w /etc/sasl2/smtpd.conf
pwcheck_method: auxprop
mech_list: plain login

Postfix should already be installed. If it's not, install postfix and go to the /etc/postfix directory.

root@localhost ~ # yum install postfix
root@localhost ~ # cd /etc/postfix

Create a backup and edit the main.cf file

root@localhost /etc/postfix # mv main.cf main.cf.sample
root@localhost /etc/postfix # nano -w main.cf
myhostname = dublin-1.eu-west-1.aws.jmk.hu
myhostname = nova-1.us-east-1.aws.jmk.hu
mydomain = localhost
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, $mydomain
mynetworks_style = host

relay_domains = jmk.hu
transport_maps = hash:/etc/postfix/transport

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_sasl_authenticated, sleep 5, permit_mynetworks, reject_unauth_destination
smtpd_relay_restrictions = permit_sasl_authenticated, sleep 5, permit_mynetworks, reject_unauth_destination
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/share/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
data_directory = /var/lib/postfix

Edit the master.cf file and enable the submission and smtps protocols.

root@localhost /etc/postfix # nano -w master.cf
submission inet n       -       n       -       -       smtpd
smtps     inet  n       -       n       -       -       smtpd

Create a backup and edit the transport file

root@localhost /etc/postfix # mv transport transport.sample
root@localhost /etc/postfix # nano -w transport
jmk.hu smtp:[mail.jmk.hu]:587

Create a map from the transport file

root@localhost /etc/postfix # postmap transport

Enable postfix to run at boot.

root@localhost /etc/postfix # systemctl enable postfix.service

Check if postfix is enabled.

root@localhost /etc/postfix # systemctl list-unit-files

Restart postfix

root@localhost /etc/postfix # systemctl restart postfix.service