Created
April 3, 2014 13:23
-
-
Save noxqsgit/9954250 to your computer and use it in GitHub Desktop.
amazon SES + ruby (Net::SMTP)
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
#!/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