# Undefined method \`mails' for #\<Net::POPMail 1\> (NoMethodErro

**URL:** <https://www.ruby-forum.com/t/undefined-method-mails-for-net-popmail-1-nomethoderro/75540>\
**Category:** Ruby\
**Created:** [November 10, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/undefined-method-mails-for-net-popmail-1-nomethoderro/75540 "2006-11-10T20:08:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![friofool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@friofool](https://www.ruby-forum.com/u/friofool)\
**Post date:** [November 10, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/undefined-method-mails-for-net-popmail-1-nomethoderro/75540/1 "2006-11-10T20:08:23Z")

</div>

Hello,  
I’m trying to do a method to get mail via pop3 server.  
I created the following script but i receive this message during  
executio :

testmail.rb:12: undefined method `mails’ for #\<Net::POPMail 1\>  
(NoMethodError)

#!/usr/bin/env ruby  
require ‘net/pop’ # I renamed the file from pop.rb to pop\_ssl.rb to  
ensure I was requiring the correct version

username = ‘removed\_email\_address@domain.invalid’  
password = ‘pass’

#Net::POP3.enable\_ssl(OpenSSL::SSL::VERIFY\_NONE)  
conn = Net::POP3.new(‘[pop.host.com](http://pop.host.com)’,110)  
conn.start(username,password)

conn.mails.each do |pop|  
msg = pop.mails[0]

# Print the ‘From:’ header line

puts msg.header.split(“\r\n”).grep(/^From: /)

# Put message to $stdout (by calling \<\<)

puts “\nFull message:\n”  
msg.all($stdout)  
end

maybe a lib problem ?

thx for your answer…

---

<div class="post-metadata">

**Author:** ![friofool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@friofool](https://www.ruby-forum.com/u/friofool)\
**Post date:** [November 10, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/undefined-method-mails-for-net-popmail-1-nomethoderro/75540/2 "2006-11-10T22:40:41Z")

</div>

There’s a mistake in your code. conn.mails return an array of the mails  
on the server, i.e an array of Net::POPMail objects. The mails method,  
instead, is a method of class Net::POP3. To make your code work, simply  
substitute the pop parameter of the block with msg and remove the first  
line of the block:

conn.mails.each do |msg|

# Print the ‘From:’ header line

puts msg.header.split("\r\n").grep(/^From: /)

# Put message to $stdout (by calling \<\<)

puts “\nFull message:\n”  
msg.all($stdout)  
end

You can also use the each (or each\_mail) methods of Net::POPMail, which  
also iterate on the mails:

conn.each\_mail do |msg|

# Print the ‘From:’ header line

puts msg.header.split("\r\n").grep(/^From: /)

# Put message to $stdout (by calling \<\<)

puts “\nFull message:\n”  
msg.all($stdout)  
end
