Handling email bounces in Rails

I created a basic CRM system for my rails app, which allows me to send weekly digests of user activity with custom text and create multi-part marketing messages that I can customize and send through the basic admin interface. I'm happy with what I put together on the send side (except for the fact that I didn't try to decipher the scope of my capabilities), but I'm concerned about how to handle rollbacks.

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

I use Google Apps to process my mail and really don't know enough about Perl to want to link to this plugin - I'm having enough headaches.

I am looking for a simple solution to handle failures in Rails. All my email will come from an address like this, which will be managed by Google Apps: " news@mydomain.com. "

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

Any guidance, links, or basic methods of working with this document are greatly appreciated.

Thanks! -A

+2


a source to share


1 answer


Ok, this turned out to be easier than I thought using the Fetcher plugin which you can find on Github. For those interested in an approach that works, here's what I did:

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

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

It also creates a daemon to run Fetcher. I tried to use this but consistently got the following error: Mysql :: Error: MySQL server left: SHOW FIELDS FROM email_blacklists

. This was the result of the daemon process disappearing before MySQL could save the record, so I gave up using the daemon and installed cron instead.

3) set up the .yml file in config which I renamed to mail.yml with your mail settings. For gmail pop, they look something like this:

development:
  type: pop
  server: pop.gmail.com
  port: 995
  ssl: true
  username: myemailaddress@gmail.com
  password: mypassword

      

Here's the code you need to handle:



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

      

Then you can throw the auto-generated mailer_daemon_fetcher.rb file into your scripts / directory.

Hope this helps someone else. If you want to check, then from the console just call MailProcessor.grab_bounces. Make sure you have email in the Inbox that you are configured to access.

+2


a source







All Articles