Last active
September 19, 2021 15:26
-
-
Save dstrunk/ff6301609bdbbcb3057d27812f8630e6 to your computer and use it in GitHub Desktop.
Quickly install Postfix and configure it to send emails from your local Vagrant box. Used on this blog post: https://goo.gl/8iv6YD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Download all postfix necessities to run PHP mail() | |
wget -P ~/ https://www.thawte.com/roots/thawte_Premium_Server_CA.pem && \ | |
sudo mv ~/thawte_Premium_Server_CA.pem /usr/local/share/ca-certificates/thawte_Premium_Server_CA.crt && \ | |
sudo update-ca-certificates ; | |
# pre-answer interactive configuration for Postfix | |
sudo debconf-set-selections <<< "postfix postfix/mailname string local.dev" | |
sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'" | |
# Install deps | |
sudo apt-get install -y postfix mailutils libsasl2-2 ca-certificates libsasl2-modules | |
# update postfix mail to use gmail | |
# per https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/ | |
# First, remove old relayhost entry | |
sudo sed -i.bak '/relayhost/,/^/d' /etc/postfix/main.cf | |
# Enter new information | |
echo " | |
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" | sudo tee -a /etc/postfix/main.cf | |
# Add Gmail username:password. | |
# This should be setup using an application-specific password in the Google | |
echo "[smtp.gmail.com]:587 [email protected]:password" | sudo tee -a /etc/postfix/sasl_passwd | |
# Add password to postfix settings | |
sudo chmod 400 /etc/postfix/sasl_passwd | |
sudo postmap /etc/postfix/sasl_passwd | |
# add CA Certs to Postfix | |
cat /etc/ssl/certs/thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem | |
# Reload | |
sudo /etc/init.d/postfix reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a small typo on line 38 (
thawt_
instead ofthawte_
), but otherwise works for me, thanks.