Skip to content

Instantly share code, notes, and snippets.

@nascimento
Created February 12, 2018 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nascimento/c1426211fa476246fe5d2082c71445b4 to your computer and use it in GitHub Desktop.
Save nascimento/c1426211fa476246fe5d2082c71445b4 to your computer and use it in GitHub Desktop.
smtp_ruby_sample.rb
#!/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'] || 'devops@arizona.global'
server = ENV['SERVER'] || 'email-smtp.us-east-1.amazonaws.com'
user = ENV['SMTP_USER'] || 'AKIAJTCYSLMQF3SA7RJA'
pass = ENV['SMTP_PASS'] || 'Aj9JPIRvd/rwRXdiECd7iQwoOXPXHKcS9m8yOgwy9ETn'
message = "TESTE EMAIL" # $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