Created
September 1, 2011 01:56
-
-
Save dgrijalva/1185230 to your computer and use it in GitHub Desktop.
Send an email through gmail
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
require 'net/smtp' | |
# Setup variables | |
from_email = "" | |
to_email = "" | |
account_login = "" | |
account_password = "" | |
# Make the email body | |
msgstr = <<END_OF_MESSAGE | |
From: God <#{from_email}> | |
To: The People of Earth <#{to_email}> | |
Subject: Stuff and things | |
Seriously. This is god. Awesome, right? | |
END_OF_MESSAGE | |
# try to send the email | |
begin | |
smtp = Net::SMTP.new('smtp.gmail.com', 587) | |
smtp.enable_starttls | |
smtp.start('localhost', account_login, account_password, :login) do |smtp| | |
smtp.send_message msgstr, from_email, to_email | |
end | |
rescue | |
puts "Couldn't send email" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment