Guest User

Untitled

a guest
Jan 31st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Program to download emails through imap.
  4. #Uses Gmail's imap extensions to download all emails of a label.
  5.  
  6. require "rubygems"
  7. require "bundler/setup"
  8. require "mailman"
  9.  
  10.  
  11. Mailman.config.ignore_stdin = true
  12.  
  13.  
  14. #Mailman.config.logger = Logger.new File.expand_path("mailman.log", __FILE__)
  15. Mailman.config.poll_interval = 15 # Set to zero if you don't want to poll
  16. Mailman.config.imap = {
  17. server: 'imap.gmail.com', port: 993, ssl: true,
  18. username: ENV['GMAIL_USERNAME'],
  19. password: ENV['GMAIL_PASSWORD'],
  20. folder: "MyLabel", # Edit This
  21. filter: "ALL"
  22. }
  23.  
  24. Mailman::Application.run do
  25.  
  26. default do
  27. puts "got a new mail " + message.subject
  28. path = "/save/my/emails/here/"
  29. File.open(path + message.message_id, "wb") {|file| file.write(message.text_part.decoded)} if message.text_part
  30. end
  31. end
Add Comment
Please, Sign In to add comment