Created
December 30, 2009 00:18
-
-
Save vinbarnes/265738 to your computer and use it in GitHub Desktop.
ideabin.rb
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'gmail' | |
unless ENV['GMAIL_USERNAME'] && ENV['GMAIL_PASSWORD'] | |
raise StandardError, <<-INFO | |
Please create a ~/.gmail_keys file with the following: | |
export GMAIL_USERNAME='username' | |
export GMAIL_PASSWORD='password' | |
and then source it before running this program. | |
INFO | |
end | |
module Kernel | |
def with_suppressed_output(file=File.new('/dev/null', 'w')) | |
$stdout.reopen(file) | |
$stderr.reopen(file) | |
yield | |
$stdout.reopen(STDOUT) | |
$stderr.reopen(STDERR) | |
end | |
end | |
gmail = Gmail.new(ENV['GMAIL_USERNAME'], ENV['GMAIL_PASSWORD']) | |
new_email = MIME::Message.generate | |
new_email.to "#{ENV['GMAIL_USERNAME']}[email protected]" | |
new_email.subject "A note from ideabin [#{Time.now}]" | |
new_email.content = ARGV.join(' ') + "\n" | |
with_suppressed_output do | |
gmail.send_email(new_email) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment