Skip to content

Instantly share code, notes, and snippets.

@sharshenov
Last active August 29, 2015 14:05
Show Gist options
  • Save sharshenov/2ce672c6e584b288d9cd to your computer and use it in GitHub Desktop.
Save sharshenov/2ce672c6e584b288d9cd to your computer and use it in GitHub Desktop.
Setup postfix gmail relay on ubuntu
# YOLO
sudo su
# Install postfix (use Internet Site configuration)
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
# Setup allowed SSL certs
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | tee -a /etc/postfix/cacert.pem
# Add to /etc/postfix/main.cf
inet_interfaces = 127.0.0.1
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
# Create /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 user@gmail.com:password
# Map credentials
postmap /etc/postfix/sasl_passwd
# Restart postfix
service postfix restart
# Test email
echo "Test succeed" | mail -s "Smtp relay test" your@email.com
# Optional - setup system emails alias
echo "root: your@email.com" >> /etc/aliases
postalias /etc/aliases
service postfix reload
echo "Test succeed" | mail -s "System alias test" root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment