Careful with that email

by

When you are building systems like my Keep on Posting or my DNSk9 that send emails there’s always the danger that you’ll accidentally fire emails from your development machine to real users. You really don’t want to do that because it’s annoying and extremely unprofessional.

It happened to me a couple of times. Thankfully, nothing serious. But I learned the lesson. That’s why in my user models now I have a safe_email method which I use instead of accessing email whenever I’m about to actually deliver a message.

The method safe_email ensures that nobody will receive a message unless I’m in production and at the same time it’s good for testing. Obviously most of the time in development and testing mode I don’t deliver emails at all, but sometimes, I make an exception:

def safe_email
  if Rails.env.production? || email.blank? # If the email is blank (or nil), let it be.
    email
  else
    "pupeno+#{email.gsub("@", "_AT_")}@pupeno.com"
  end
end

3 responses to “Careful with that email”

  1. Thomas Maurer Avatar
    Thomas Maurer

    Theres’s a gem for that too :)

    https://github.com/myronmarston/mail_safe

  2. Luke Avatar

    I like using interceptors for this – that way I don’t have to make any code changes:
    http://pastie.org/2228288

  3. nathanvda Avatar
    nathanvda

    Another alternative is to use http://mailcatcher.me/

Leave a Reply

You may also like:

Hi, I'm Pablo, this is my web site. You can follow me or connect with me:

Or get new content delivered directly to your inbox.

Join 4,048 other subscribers

I'm writing a book

Stack of copies of How to Hire and Manage Remote Teams

How to Hire and Manage Remote Teams, where I distill all the techniques I've been using to build and manage distributed teams for the past 10 years.

I write about:

announcement blogging book book review book reviews books building Sano Business C# Clojure ClojureScript Common Lisp database Debian Esperanto Git ham radio history idea Java Keep on Posting Kubuntu Lisp Non-Fiction OpenID programming Python Radio Society of Great Britain Rails rant re-frame release Ruby Ruby on Rails Sano science science fiction security self-help Star Trek startups technology Ubuntu web WordPress

I've been writing for a while:

Mastodon

%d bloggers like this: