Skip to content

Instantly share code, notes, and snippets.

@koki0702
Last active December 16, 2015 10:28
Show Gist options
  • Save koki0702/5419993 to your computer and use it in GitHub Desktop.
Save koki0702/5419993 to your computer and use it in GitHub Desktop.
This shell script enable your MacOSX to send e-mail from 'mail' command through a gmail account. You don't worry about 'Outbound Port 25 Blocking'
#!/bin/sh
# Shell script to mail for mac OSX
# =====================================================================
# This shell script enable your MacOSX to send e-mail from 'mail' command
# through a gmail account.
# Set your gmail address and password below
#
# c.f http://www.happytrap.jp/blogs/2012/02/25/8313/
########################################
MAIL_ADDRESS="xxxxx@gmail.com"
PASS_WORD="xxxxxxxxx"
########################################
#configure mail setting
mkdir -p /Library/Server/Mail/Data/spool
/usr/sbin/postfix start
#for googleTest library
ln -s /usr/bin/mail /bin/mail
touch /etc/postfix/sasl_passwd
echo "smtp.gmail.com:587 $MAIL_ADDRESS:$PASS_WORD" > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
rm -rf /etc/postfix/sasl_passwd
#Outbound Port 25 Blocking
POSTFIX_CONFIG='# Minimum Postfix-specific configurations.
mydomain_fallback = localhost
mail_owner = _postfix
setgid_group = _postdrop
relayhost=smtp.gmail.com:587
# Enable SASL authentication in the Postfix SMTP client.
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=
# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom'
echo "$POSTFIX_CONFIG" >> /etc/postfix/main.cf
#Postfix load
launchctl load -w /System/Library/LaunchDaemons/org.postfix.master.plist
postfix reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment