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

Error saving attachment #28

Closed cas27 closed 11 years ago

cas27 commented 14 years ago

Here is my code

  vmFolder = '/home/user/vm/'
  email = gmail.inbox.emails(:unread).first
  email.attachments[0].save_to_file(vmFolder)

Getting this error

/var/lib/gems/1.8/gems/mail-2.2.5/lib/mail/message.rb:1251:in `method_missing':
undefined method `save_to_file' for #<Mail::Part:0xb74e9c1c> (NoMethodError)
ButuzGOL commented 14 years ago

I have the same problem (

stefanobernardi commented 13 years ago

Has anyone solved this?

cas27 commented 13 years ago

Yeah here is how I got it to work

File.open(saveLocation,"w+") { |local_file| local_file << email.attachments.first.decoded }

stefanobernardi commented 13 years ago

Yup I got it too with email.attachments.each do |a| file = File.new("attachments/" + a.filename, "w+") file << a.decoded file.close

do your stuff here

      File.delete("attachments/" + a.filename) #just in case
    end
stefanobernardi commented 13 years ago

Thanks for the quick reply anyways!

stefanwille commented 12 years ago

I think the cause here is that both the 'mail' gem and 'ruby-gmail' define a class Mail::Part, and the former gem wins the naming conflict.

macedo commented 12 years ago

This works for me too! ;)

myobie commented 11 years ago

Sorry, this was a mistake in the readme, the mail gem doesn't offer that method.