Skip to content

Instantly share code, notes, and snippets.

@noxqsgit
Created April 3, 2014 13:23
Show Gist options
  • Save noxqsgit/9954250 to your computer and use it in GitHub Desktop.
Save noxqsgit/9954250 to your computer and use it in GitHub Desktop.
amazon SES + ruby (Net::SMTP)
#!/usr/bin/env ruby
require 'net/smtp'
unless (2..3).include? ARGV.length
puts 'Usage: mail.rb SUBJECT TO [FROM]'
exit 1
end
subject, to, from_ = ARGV
from = from_ || ENV['FROM'] || '...'
server = ENV['SERVER'] || 'email-smtp.eu-west-1.amazonaws.com'
user = ENV['SMTP_USER'] || '...'
pass = ENV['SMTP_PASS'] || '...'
message = $stdin.read
mail = <<EOF
From: #{from}
To: #{to}
Subject: #{subject}
Date: #{Time.now}
#{message}
EOF
conn = Net::SMTP.new server, 465
conn.enable_tls
conn.start 'localhost', user, pass, :login
conn.send_message mail, from, *to.split(/\s*,\s*/)
conn.finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment