Skip to content

Instantly share code, notes, and snippets.

@costa
Last active March 8, 2018 15:32
Show Gist options
  • Save costa/a325e7fdc5a803e1e5425fd36a784fe7 to your computer and use it in GitHub Desktop.
Save costa/a325e7fdc5a803e1e5425fd36a784fe7 to your computer and use it in GitHub Desktop.
docker-machine ssh some-gcloud-machine 'curl <THIS-GIST-RAW-URL> | sudo sh'
echo "postfix postfix/mailname string ido-dev.bandmanage.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y postfix libsasl2-modules || exit 2
grep -vE 'default_transport = error|relay_transport = error' /etc/postfix/main.cf > /tmp/main.cf
cat /tmp/main.cf > /etc/postfix/main.cf
echo '
relayhost = [smtp.sendgrid.net]:2525
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
header_size_limit = 4096000
smtp_sasl_security_options = noanonymous
' >> /etc/postfix/main.cf
rm /tmp/main.cf
curl -s -H Metadata-Flavor:Google http://metadata/computeMetadata/v1/project/attributes/sendgrid-sasl-passwd > /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
rm /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd.db || exit 1
/etc/init.d/postfix restart
DEBIAN_FRONTEND=noninteractive apt-get install -y mailutils || exit 2
@costa
Copy link
Author

costa commented Mar 8, 2018

Note that your GCE project must have sendgrid-sasl-passwd metadata in order for this to work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment