Skip to content

Instantly share code, notes, and snippets.

@coreyward
Created November 27, 2010 19:31
Show Gist options
  • Save coreyward/718195 to your computer and use it in GitHub Desktop.
Save coreyward/718195 to your computer and use it in GitHub Desktop.
Fetch emails from a Gmail account via IMAP for processing
# Via http://blog.ethanvizitei.com/2008/06/using-ruby-for-imap-with-gmail.html
imap = Net::IMAP.new(@config['server'],@config['port'],true)
imap.login(@config['username'], @config['password'])
imap.select('INBOX')
imap.search(["NOT", "DELETED"]).each do |message_id|
MailFetcher.receive(imap.fetch(message_id, "RFC822")[0].attr["RFC822"])
imap.store(message_id, "+FLAGS", [:Deleted])
end
imap.logout()
imap.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment