# Daemons,Email and DB

**URL:** <https://www.ruby-forum.com/t/daemons-email-and-db/123770>\
**Category:** Rails\
**Created:** [December 20, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/daemons-email-and-db/123770 "2007-12-20T13:28:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reddaly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@reddaly](https://www.ruby-forum.com/u/reddaly)\
**Post date:** [December 20, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/daemons-email-and-db/123770/1 "2007-12-20T13:28:40Z")

</div>

Hey

Here is my code:

* * *

#!/usr/bin/env ruby

#You might want to change this  
ENV[“RAILS\_ENV”] ||= “development”

require File.dirname( **FILE** ) + “/…/…/config/environment”  
require “net/pop”

$running = true;  
Signal.trap(“TERM”) do  
$running = false  
end

while($running) do

Net::POP3.start(‘[mail.mylittlesecret.co.uk](http://mail.mylittlesecret.co.uk)’,110,  
‘[test+mylittlesecret.co.uk](http://test+mylittlesecret.co.uk)’,‘password’) do |mail|  
unless mail.mails.empty?

```
   mail.mails.each do |n|
     #some saving goes here e.g.
      #email = Email.new
        #email.from = n.from
        #email.body = n.body
        #email.save
     ActiveRecord::Base.logger << "messages saved\n"
   end
  else
    ActiveRecord::Base.logger << "Error\n"
  end
end

```

sleep 10

## end

Is there a way I can split the email up like this (where the comments  
are)? I’ve looked through the Net::pop documentation but I couldnt see  
anything about saving to a database, only file based.

Thanks, Red
