Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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']}+ideabin@gmail.com"
- 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
Add Comment
Please, Sign In to add comment