Skip to content

Instantly share code, notes, and snippets.

@otiai10
Created March 8, 2013 10:33
Show Gist options
  • Save otiai10/5115589 to your computer and use it in GitHub Desktop.
Save otiai10/5115589 to your computer and use it in GitHub Desktop.
mail, それもgmail
require 'rubygems'
require 'gmail' # sudo gem install ruby-gmail
require 'conf' # ただの設定ファイル
gmail = Gmail.new(USERNAME,PASSWORD)
puts 'read'
mails = gmail.inbox.emails(:read).map do |mail|
puts "Subject: #{mail.subject}"
end
puts 'unread'
mails = gmail.inbox.emails(:unread).map do |mail|
puts "==========================================================="
puts "Subject: #{mail.subject}"
#本文処理
if !mail.text_part && !mail.html_part
puts "body: " + mail.body.decoded.encode("UTF-8", mail.charset)
elsif mail.text_part
puts "text: " + mail.text_part.decoded
elsif mail.html_part
puts "html: " + mail.html_part.decoded
end
end
gmail.disconnect
@otiai10
Copy link
Author

otiai10 commented Mar 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment