Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `message' #39

Open
macedo opened this issue Jan 19, 2012 · 9 comments
Open

NoMethodError: undefined method `message' #39

macedo opened this issue Jan 19, 2012 · 9 comments
Labels

Comments

@macedo
Copy link

macedo commented Jan 19, 2012

I get this error when i try to download attachments from any email. I've alredy try ruby 1.9.2 and 1.8.7.

@novito
Copy link

novito commented Apr 3, 2012

I am having the same problem under ruby 1.9.3

@myobie
Copy link
Collaborator

myobie commented Dec 19, 2012

Can you post a code example? And can you upgrade and try the newest gem version?

@refriedchicken
Copy link
Contributor

I am also having this issue on Ruby 1.9.3 using 0.3.0.

folder = "/home/refriedchicken/downloads"
Gmail.new('username','password') do |g|
g.inbox.emails(:unread, :from => "[email protected]").each do |e|
if !e.message.attachments.empty?
e.message.save_attachments_to(folder)
e.mark(:read)
e.archive!
end
end
end

NoMethodError: undefined method message' for #<Mail::Message:0x0000000273f800> from /home/refriedchicken/.rvm/gems/ruby-1.9.3-p374/gems/mail-2.5.3/lib/mail/message.rb:1289:inmethod_missing'
from /home/refriedchicken/.rvm/gems/ruby-1.9.3-p374/gems/ruby-gmail-0.3.0/lib/gmail/message.rb:101:in method_missing' from (irb):30:inblock (2 levels) in irb_binding'
from (irb):29:in each' from (irb):29:inblock in irb_binding'
from /home/refriedchicken/.rvm/gems/ruby-1.9.3-p374/gems/ruby-gmail-0.3.0/lib/gmail.rb:24:in initialize' from (irb):28:innew'
from (irb):28
from /home/refriedchicken/.rvm/rubies/ruby-1.9.3-p374/bin/irb:13:in `

'

@ghost ghost assigned myobie Jan 23, 2013
@marcusfloriano
Copy link

Hi,

I solved with code below. The ruby version is ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

File.open(File.join("imgs", file.filename), "w+b", 0644 ) { |f| f.write file.body.decoded }

Thank's

@ghost
Copy link

ghost commented Oct 15, 2013

I am too face the same problem. I have using ruby 2.0.0-p247 and ruby-gmail-0.3.0.
Any work around?

@rcho
Copy link

rcho commented Dec 1, 2013

I got the same problem, it appears the save_attachments_to method doesnt exist or has been deprecated by the mail gem. I was able to handle my attachments like so

message.attachments.each do |attachment|
File.open("/home/rcho/Downloads/#{attachment.filename}", "w+b", 0644) { |f| f.write attachment.body.decoded }
end

source: https://github.com/mikel/mail#testing-and-extracting-attachments

@curpeng
Copy link

curpeng commented Mar 13, 2014

Seems that in version 0.3.0 author made method 'message' private. At master I see that this method is public, so I assume that it was done mistakenly. For fast fixing this we can use send:
g.inbox.emails(:unread, :from => "[email protected]").each do |e|
e.send(:message).save_attachments_to(folder)
end

@Dreyfuzz
Copy link

@rcho's method doesn't work for me, which makes sense since it's still relying on the message method. I had no better results using emails.send(:message).save_attachments_to(folder). I get undefined method `save_attachments_to' for #Mail::Message:0x00000101469608

@myobie
Copy link
Collaborator

myobie commented Mar 28, 2014

@Dreyfuzz @dolgishev I've merged a PR that updated the README. Can you try to save the attachments manually?

The #save_attachments_to method was very out of date and the new example should work.

@myobie myobie removed their assignment Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants