# Newbie question about pop3 access

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-pop3-access/78964>\
**Category:** Ruby\
**Created:** [December 11, 2006, 2:06am UTC](https://www.ruby-forum.com/t/newbie-question-about-pop3-access/78964 "2006-12-11T02:06:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![furby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@furby](https://www.ruby-forum.com/u/furby)\
**Post date:** [December 11, 2006, 2:06am UTC](https://www.ruby-forum.com/t/newbie-question-about-pop3-access/78964/1 "2006-12-11T02:06:30Z")

</div>

I am rather new to Ruby and I want to write a program to play around  
with email. I can connect to my chosen pop3 server and iterate through  
the mail relatively easily. But my question is how to I parse out the  
mail? How do I access the From, Subject, and body? Are there any easy  
way’s to do this in Ruby without adding lots of new programming  
libraries (I found a couple that would make this really easy, but I  
don’t want to drain my bank account by spending money on them), but I  
can’t figure out how to do this in straight Ruby…

Do I have to parse out the entire message, or are there easy commands  
in the normal net/pop3 library?

---

<div class="post-metadata">

**Author:** ![furby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@furby](https://www.ruby-forum.com/u/furby)\
**Post date:** [December 11, 2006, 2:14am UTC](https://www.ruby-forum.com/t/newbie-question-about-pop3-access/78964/2 "2006-12-11T02:14:32Z")

</div>

On Mon, Dec 11, 2006 at 10:05:06AM +0900, furby wrote:

> in the normal net/pop3 library?  
> I don’t quite see how you expect to have anything drain your back  
> account. Have you seen the following?

[http://raa.ruby-lang.org/search.rhtml?search=mail](http://raa.ruby-lang.org/search.rhtml?search=mail)

– Thomas A.

---

<div class="post-metadata">

**Author:** ![furby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@furby](https://www.ruby-forum.com/u/furby)\
**Post date:** [December 11, 2006, 2:20am UTC](https://www.ruby-forum.com/t/newbie-question-about-pop3-access/78964/3 "2006-12-11T02:20:32Z")

</div>

This is mostly pure speculation based on prior knowledge that hasn’t  
been tested. But, try this:

```
require 'net/pop'

 Net::POP3.start('pop.example.com', 110,
                 'YourAccount', 'YourPassword') do |pop|
   if pop.mails.empty?
     puts 'No mail.'
   else
     i = 0
     pop.each_mail do |m| # or "pop.mails.each ..." /^From:

```

(.\*?)$/.match(m.pop) # \<—  
puts $1  
end  
puts “#{pop.mails.size} mails popped.”  
end  
end

Everything that isn’t by the # \<— is taken from the net/pop docs.

dan

---

<div class="post-metadata">

**Author:** ![furby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@furby](https://www.ruby-forum.com/u/furby)\
**Post date:** [December 11, 2006, 2:31pm UTC](https://www.ruby-forum.com/t/newbie-question-about-pop3-access/78964/4 "2006-12-11T14:31:31Z")

</div>

Actually, I hadn’t seen that. All the libraries I found so far cost  
money (From $99 up to $450)… I’ll check it out.
