Created
April 1, 2013 02:12
-
-
Save 5eleven/5282856 to your computer and use it in GitHub Desktop.
Integrates gmail with Ruby
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" | |
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