Postfix

From ◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞
Jump to: navigation, search

Set up MX and A records in your DNS settings first. Create an A record with the texts mail and ip address for the fields. Create an MX record with your specified domain.name and 5 for the priority field. Wait 48 hours for this to propograte.

Installation

sudo apt-get update
sudo apt-get install postfix mailutils libsasl2-2 libsasl2-modules sasl2-bin

Edit emacs /etc/default/saslauthd file and set START=yes

If you need to reconfigure an installed Postfix, use: dpkg-reconfigure postfix

Configuration

main.cf
sudo emacs /etc/postfix/main.cf
myhostname = brandonphuong.net
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

append_dot_mydomain = no
readme_directory = no

smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.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

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_domains = brandonphuong.net
virtual_alias_maps = hash:/etc/postfix/virtual
myorigin = /etc/mailname
mydestination = brandonphuong.net, localhost.net, localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

relayhost =
smtpd_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
broken_sasl_auth_clients = yes
virtual & mailname

Create a file, emacs /etc/postfix/virtual and add @brandonphuong.net brandonphuong@gmail.com

Create another file with emacs /etc/mailname and add mail.domain.com

sasl_passwd

emacs /etc/postfix/sasl_passwd and add the following: smtp.gmail.com:587 some.user@gmail.com:PASSWORD

Permissions

Set permissions to:

chmod 600 /etc/postfix/sasl_passwd*
chown -R postfix:postfix /etc/postfix/.

Update the Configuration

Rebuild the "hash" then restart Postfix.

sudo postmap /etc/postfix/virtual
sudo service postfix restart

Troubleshooting

  • Check with the postconf command that the domain aliases and alias file have been setup properly: postconf -n | grep virtual[1]
  • Check the postfix status: sudo service postfix status
  • Check that it is running on port 25 with Netstat: sudo netstat -ltnp | grep 25[2]
  • Verify DNS settings of the domain. It's necessary to ensure that the MX records for your domain are pointing to the right server. Use a dig command to do so: dig brandonphuong.net mx
  • Error logs: /var/log/mail.log
  • Use http://send-email.org to send an email.

References

  1. http://www.binarytides.com/postfix-mail-forwarding-debian/
  2. https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04