dcparker / ruby-gmail

A Rubyesque interface to Gmail. Connect to Gmail via IMAP and manipulate emails and labels. Send email with your Gmail account via SMTP. Includes full support for parsing and generating MIME messages.
http://dcparker.github.com/ruby-gmail
792 stars 123 forks source link

Lack of clear documentation regarding reading messages. #36

Closed ghost closed 11 years ago

ghost commented 13 years ago

Hello, Im still trying to read a message from within the inbox. I have connected to the server, found the list of messages, but am unsure what method I should be using to actually view the body of the message.

Using: gmail.inbox.emails(:unread, :from => mailaddress).each do |email| email.message Popped the error "undefined method: message" This pops up for .read, .body.. etc Am I doing it wrong?

pfarrell commented 12 years ago

This form works for me...

gmail = Gmail.new(credentials.username, credentials.password) do |gmail| inbox = gmail.inbox inbox.emails(:unread).each do |email| puts email.body emails.body.parts.each do |part| puts part.decoded end end end

I agree with you about lack of docs.

pfarrell commented 12 years ago

ruby-gmail wraps TMail, so the missing docs can be found by looking at it: http://tmail.rubyforge.org/rdoc/index.html

johnnygoodman commented 12 years ago

Thanks for your comments pfarrell, helped me out!

rderoldan1 commented 12 years ago

@pfarrell did you know how to get the time of the mail. this is my code

messages = ""    
gmail.inbox.emails(:unread).each do |email|
  email.from.each do |info|
    messages += info.name
  end
  messages += email.subject+"\n\n"
end
myobie commented 11 years ago

Thanks for all the tips here and I am going to close this out. If anyone has time to fork and update the README it would be appreciated.