Created
August 22, 2012 07:52
-
-
Save imwilsonxu/3423574 to your computer and use it in GitHub Desktop.
Send Email 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
# -*- coding: utf-8 -*- | |
# Usage: | |
# export gmail_username=xxx | |
# export gmail_password=yyy | |
# ruby gmail.rb | |
require 'rubygems' | |
require 'mail' | |
smtp = { | |
:address => 'smtp.gmail.com', | |
:port => 587, | |
:domain => 'gmail.com', | |
:user_name => ENV['gmail_username'], | |
:password => ENV['gmail_password'], | |
:enable_starttls_auto => true | |
} | |
Mail.defaults { delivery_method :smtp, smtp } | |
mail = Mail.new do | |
from '[email protected]' | |
to ['[email protected]'] | |
subject 'Hello from Ruby' | |
body 'Hello Gmail' | |
end | |
mail.deliver! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment