Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Program to download emails through imap.
- #Uses Gmail's imap extensions to download all emails of a label.
- require "rubygems"
- require "bundler/setup"
- require "mailman"
- Mailman.config.ignore_stdin = true
- #Mailman.config.logger = Logger.new File.expand_path("mailman.log", __FILE__)
- Mailman.config.poll_interval = 15 # Set to zero if you don't want to poll
- Mailman.config.imap = {
- server: 'imap.gmail.com', port: 993, ssl: true,
- username: ENV['GMAIL_USERNAME'],
- password: ENV['GMAIL_PASSWORD'],
- folder: "MyLabel", # Edit This
- filter: "ALL"
- }
- Mailman::Application.run do
- default do
- puts "got a new mail " + message.subject
- path = "/save/my/emails/here/"
- File.open(path + message.message_id, "wb") {|file| file.write(message.text_part.decoded)} if message.text_part
- end
- end
Add Comment
Please, Sign In to add comment