Skip to content

Instantly share code, notes, and snippets.

@zapnap
Created March 5, 2011 17:17
Show Gist options
  • Save zapnap/856517 to your computer and use it in GitHub Desktop.
Save zapnap/856517 to your computer and use it in GitHub Desktop.
Add Amazon SES support to Rubber / EC2 config
# ------------------------
# add the following packages to rubber.yml:
# ------------------------
packages: [postfix, libio-socket-ssl-perl, libxml-libxml-perl, unzip]
# ------------------------
# add to config/rubber/custom-setup.rb:
# ------------------------
namespace :rubber do
namespace :base do
# Install and configure Amazon SES for mail transport handling (via Postfix)
after "rubber:base:custom_install", "rubber:base:install_amazon_ses"
task :install_amazon_ses do
cloud_provider = rubber_env.cloud_providers[rubber_env.cloud_provider]
rubber.sudo_script 'install_amazon_ses', <<-ENDSCRIPT
export AWS_SES_DIR=/mnt/mail/amazon
if [ ! -d $AWS_SES_DIR ]; then
mkdir -p $AWS_SES_DIR
builtin cd $AWS_SES_DIR
curl -L "http://aws-catalog-download-files.s3.amazonaws.com/AmazonSES-2011-02-02.zip" -o "ses.zip"
unzip "ses.zip"
echo "AWSAccessKeyId=#{cloud_provider.access_key}" > $AWS_SES_DIR/aws-credentials
echo "AWSSecretKey=#{cloud_provider.secret_access_key}" >> $AWS_SES_DIR/aws-credentials
mkdir -p /usr/local/lib/site_perl
cp $AWS_SES_DIR/bin/SES.pm /usr/local/lib/site_perl
chmod ugo+x $AWS_SES_DIR/bin/*.pl
chown -R mail:mail $AWS_SES_DIR
chmod 600 $AWS_SES_DIR/aws-credentials
fi
ENDSCRIPT
end
end
end
# ------------------------
# config/rubber/common/postfix-master.cf (the last couple lines were added)
# ------------------------
<%
@path = '/etc/postfix/master.cf'
%>
smtp inet n - - - - smtpd
pickup fifo n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
qmgr fifo n - n 300 1 qmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - - - - smtp
relay unix - - - - - smtp
-o smtp_fallback_relay=
showq unix n - - - - showq
error unix - - - - - error
retry unix - - - - - error
discard unix - - - - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - - - - lmtp
anvil unix - - - - 1 anvil
scache unix - - - - 1 scache
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
aws-email unix - n n - - pipe
flags=R user=mail argv=/mnt/mail/amazon/bin/ses-send-email.pl -r -k /mnt/mail/amazon/aws-credentials -e https://email.us-east-1.amazonaws.com -f ${sender} ${recipient}
# ------------------------
# config/rubber/common/postfix-main.cf
# ------------------------
<%
@path = '/etc/postfix/main.cf'
%>
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
readme_directory = no
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
myhostname = <%= RUBBER_ENV %>
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = <%= RUBBER_ENV %>, localhost.localdomain, localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
# Amazon SES
default_transport = aws-email
relay_transport = smtp
relayhost =
# ------------------------
# See http://netwiser.blogspot.com/2011/02/setup-amazon-ses-to-relay-email-by.html for more information.
# ------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment