views:

22

answers:

1

Hi there,

I've built a very basic CRM system for my rails app that allows me to send weekly user activity digests with custom text and create multi-part marketing messages which I can configure and send through a basic admin interface. I'm happy with what I've put together on the send-side of things (minus the fact that I haven't tried to volume test its capabilities), but I'm concerned about how to handle bounce-backs.

I came across this plugin with associated scripts: http://github.com/kovyrin/bounces-handler

I'm using Google Apps to handle my mail and really don't know enough about Perl to want to mess with the above plugin - I have enough headaches.

I'm looking for a simple solution for processing bounce-backs in Rails. All my email will go out from an address like this which will be managed in Google Apps: "[email protected]."

What's the best workflow for this? Can anyone post an example solution they're using keeping in mind the fact that I'm using Google Apps for the mail?

Any guidance, links, or basic workflow best-practices to handle this would be greatly appreciated.

Thanks! -A

A: 

Ok, this has proven to be easier then I thought using the Fetcher plugin which you can find on Github. For those interested in an approach that appears to work, here's what I've done:

1) Install the Fetcher plugin like so: script/plugin install git://github.com/look/fetcher.git

2) The instructions suggest you run a generator to create a daemon like so: script/generate fetcher_daemon MailerDaemon. I suggest doing this since it will generate a YML file in config/ which you can modify with your mail server info (in my case Gmail).

It also generates a daemon to run Fetcher. I tried using this but consistently got the following error: Mysql::Error: MySQL server has gone away: SHOW FIELDS FROM email_blacklists. This was the result of the daemon process disappearing before the MySQL could store the record so I abandoned using the daemon and setup a cron instead.

3) configure the .yml file in config which i renamed to mail.yml with your mail settings. For gmail pop, they look something lik this:

development:
  type: pop
  server: pop.gmail.com
  port: 995
  ssl: true
  username: [email protected]
  password: mypassword

Here's the code you'll need to process:

models/mail_processor.rb

class MailProcessor < ActionMailer::Base
  def receive(email)
    email = EmailBlacklist.find_or_create_by_email(email.to.first)

  end
  def self.grab_bounces
    config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
    config = config[RAILS_ENV].to_options
    fetcher = Fetcher.create({:receiver => MailProcessor}.merge(config))
    fetcher.fetch
  end
end

lib/tasks/mail.rake

namespace :email do
  desc "sends various types of marketing and automated emails and processes bouncebacks"
  task(:process_bounces => :environment) do
    MailProcessor.grab_bounces
  end
end

You can then toss the auto-generated mailer_daemon_fetcher.rb file in your scripts/ directory.

Hope this helps someone else. If you want to test then, from the console simply call MailProcessor.grab_bounces. Make sure you have some email in the inbox that you're configured to access.

aressidi