Skip to content

Instantly share code, notes, and snippets.

@imwilsonxu
Created August 22, 2012 07:52
Show Gist options
  • Save imwilsonxu/3423574 to your computer and use it in GitHub Desktop.
Save imwilsonxu/3423574 to your computer and use it in GitHub Desktop.
Send Email With Ruby
# -*- 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 'imwilsonxu@gmail.com'
to ['imwilsonxu@gmail.com']
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