Created
February 12, 2018 01:22
-
-
Save nascimento/c1426211fa476246fe5d2082c71445b4 to your computer and use it in GitHub Desktop.
smtp_ruby_sample.rb
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'] || '[email protected]' | |
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