Skip to content

Instantly share code, notes, and snippets.

@imwilsonxu
Created August 22, 2012 07:52
Show Gist options
  • Select an option

  • Save imwilsonxu/3423574 to your computer and use it in GitHub Desktop.

Select an option

Save imwilsonxu/3423574 to your computer and use it in GitHub Desktop.

Revisions

  1. imwilsonxu created this gist Aug 22, 2012.
    28 changes: 28 additions & 0 deletions gmail.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # -*- 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!