Created
December 8, 2015 09:27
-
-
Save umar-siddiqui/34b549a942b7c5d21529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mailman' | |
Mailman.config.imap = { | |
server: 'imap.gmail.com', | |
port: 993, # you usually don't need to set this, but it's there if you need to | |
ssl: true, | |
# Use starttls instead of ssl (do not specify both) | |
#starttls: true, | |
username: 'umar@treeni.com', | |
password: 'fresh786' | |
} | |
Mailman::Application.run do | |
default do | |
begin | |
p "Found a new message" | |
p message.from.first # message.from is an array | |
p message.to.first # message.to is an array again.. | |
p message.subject | |
p message.attachments.first.filename | |
rescue Exception => e | |
Mailman.logger.error "Exception occurred while receiving message:n#{message}" | |
Mailman.logger.error [e, *e.backtrace].join("n") | |
end | |
end | |
end | |
tmail.attachments.each do |tattch| | |
fn = tattch.filename | |
begin | |
File.open( fn, "w+b", 0644 ) { |f| f.write tattch.body.decoded } | |
rescue Exception => e | |
logger.error "Unable to save data for #{fn} because #{e.message}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment