Guest User

Untitled

a guest
May 17th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'gmail'
  3.  
  4. unless ENV['GMAIL_USERNAME'] && ENV['GMAIL_PASSWORD']
  5. raise StandardError, <<-INFO
  6.  
  7. Please create a ~/.gmail_keys file with the following:
  8.  
  9. export GMAIL_USERNAME='username'
  10. export GMAIL_PASSWORD='password'
  11.  
  12. and then source it before running this program.
  13. INFO
  14. end
  15. module Kernel
  16. def with_suppressed_output(file=File.new('/dev/null', 'w'))
  17. $stdout.reopen(file)
  18. $stderr.reopen(file)
  19. yield
  20. $stdout.reopen(STDOUT)
  21. $stderr.reopen(STDERR)
  22. end
  23. end
  24.  
  25. gmail = Gmail.new(ENV['GMAIL_USERNAME'], ENV['GMAIL_PASSWORD'])
  26. new_email = MIME::Message.generate
  27. new_email.to "#{ENV['GMAIL_USERNAME']}+ideabin@gmail.com"
  28. new_email.subject "A note from ideabin [#{Time.now}]"
  29. new_email.content = ARGV.join(' ') + "\n"
  30. with_suppressed_output do
  31. gmail.send_email(new_email)
  32. end
Add Comment
Please, Sign In to add comment