Skip to content

Instantly share code, notes, and snippets.

@5eleven
Created April 1, 2013 02:12
Show Gist options
  • Save 5eleven/5282856 to your computer and use it in GitHub Desktop.
Save 5eleven/5282856 to your computer and use it in GitHub Desktop.
Integrates gmail with Ruby
require "net/smtp"
require "time" # for rfc2822
# sender
from_addr = "insert_from_address_here"
# receiver
to_addr = "insert_receiver_address_here"
mail_content = <<END_OF_CONTENT
From: #{from_addr}
To: #{to_addr}
Subject: Just a test
Date: #{Time.now.rfc2822}
Just a test of sending email via Ruby.
END_OF_CONTENT
smtp = Net::SMTP.new("smtp.gmail.com",587)
smtp.enable_starttls
smtp.start("smtp.gmail.com","your_gmail_username","your_gmail_password",:login) do
smtp.send_message(mail_content, from_addr, to_addr)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment