Guest User

Untitled

a guest
Apr 13th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # ghetto gmail sms notification while I wait for GPush and when MsgPush fail
  3. # Usage: ./gmail_sms_push.rb &
  4.  
  5. require 'net/imap'
  6. require 'net/smtp'
  7.  
  8. domain = 'yourdomain.com'
  9. from = "user@#{domain}"
  10. username = 'username'
  11. password = 'password'
  12. sms_email = '1234567890@txt.att.net'
  13. new_mail_msg = "You've got mail!"
  14. sleep_interval = 30
  15.  
  16. (imap = Net::IMAP.new('imap.gmail.com', 993, true)).login(username, password)
  17.  
  18. begin
  19. imap.select('INBOX')
  20. new_uid = imap.search(['ALL']).last
  21. @last_uid ||= new_uid
  22.  
  23. if new_uid > @last_uid
  24. (smtp = Net::SMTP.new('smtp.gmail.com', 587)).enable_starttls_auto
  25. smtp.start(domain, username, password, :plain) { |smtp| smtp.send_message(new_mail_msg, from, sms_email) }
  26. @last_uid = new_uid
  27. end
  28.  
  29. sleep sleep_interval
  30. end while true
Add Comment
Please, Sign In to add comment