Created
October 25, 2012 19:32
-
-
Save jjulian/3954895 to your computer and use it in GitHub Desktop.
Send an email using Ruby's standard lib.
This file contains hidden or 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
require 'net/smtp' | |
host = 'smtp.gmail.com' | |
port = 587 | |
from = '[email protected]' | |
password = 'secret' | |
just_test = false | |
to = '[email protected]' | |
msgstr = <<END_OF_MESSAGE | |
From: #{from} | |
To: #{to} | |
Subject: testing Net::SMTP | |
Message body here. | |
END_OF_MESSAGE | |
smtp = Net::SMTP.new(host, port) | |
smtp.set_debug_output $stderr | |
smtp.enable_starttls_auto | |
if just_test | |
begin | |
smtp.start('localhost', from, password, :login) | |
smtp.finish | |
puts "TEST OK" | |
rescue Net::SMTPAuthenticationError | |
puts "TEST FAILED" | |
end | |
else | |
smtp.start('localhost', from, password, :login) do |smtp| | |
smtp.send_message msgstr, from, to | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment