Skip to content

Instantly share code, notes, and snippets.

@vinbarnes
Created December 30, 2009 00:18
Show Gist options
  • Save vinbarnes/265738 to your computer and use it in GitHub Desktop.
Save vinbarnes/265738 to your computer and use it in GitHub Desktop.
ideabin.rb
#!/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