Created
March 8, 2013 10:33
-
-
Save otiai10/5115589 to your computer and use it in GitHub Desktop.
mail, それもgmail
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 '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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://shoken.hatenablog.com/entry/20120401/p1