<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: pop3 code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 18:52:13 GMT</pubDate>
    <description>DZone Snippets: pop3 code</description>
    <item>
      <title>Using POP3 to Retrieve Email for Rails App</title>
      <link>http://snippets.dzone.com/posts/show/4214</link>
      <description>Put this in a file called "inbox" in the scripts/ directory of your Rails app. change the host, username, and password to match.&lt;br /&gt;&lt;br /&gt;Set up a cron job to run this script every so often (frequency depends on your needs).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;&lt;br /&gt;require 'net/pop'&lt;br /&gt;require File.dirname(__FILE__) + '/../config/environment'&lt;br /&gt;&lt;br /&gt;logger = RAILS_DEFAULT_LOGGER&lt;br /&gt;&lt;br /&gt;logger.info "Running Mail Importer..." &lt;br /&gt;Net::POP3.start("localhost", nil, "username", "password") do |pop|&lt;br /&gt;  if pop.mails.empty?&lt;br /&gt;    logger.info "NO MAIL" &lt;br /&gt;  else&lt;br /&gt;    pop.mails.each do |email|&lt;br /&gt;      begin&lt;br /&gt;        logger.info "receiving mail..." &lt;br /&gt;        Notifier.receive(email.pop)&lt;br /&gt;        email.delete&lt;br /&gt;      rescue Exception =&gt; e&lt;br /&gt;        logger.error "Error receiving email at " + Time.now.to_s + "::: " + e.message&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;logger.info "Finished Mail Importer." &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 26 Jun 2007 17:40:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4214</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
  </channel>
</rss>
