Skip to content

Instantly share code, notes, and snippets.

@dgrijalva
Created September 1, 2011 01:56
Show Gist options
  • Save dgrijalva/1185230 to your computer and use it in GitHub Desktop.
Save dgrijalva/1185230 to your computer and use it in GitHub Desktop.
Send an email through gmail
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