Avatar Edgar González

  • Random
  • Archive
  • RSS

Rails 3 :: Not abandon sending mail within ActionMailer action

In ActionMailer (Rails 3) you can’t decide not to send an email. For instance, you have the following mailer:

class FooMailer < ActionMailer::Base
  def bar_email
    if some_condition
      mail(...)
    else
      # Can I do nothing? No :-(
    end
  end
end

If you invoke FooMailer.bar_email.deliver!, when same_condition is false you will get the following error:

ArgumentError: A sender (Return-Path, Sender or From) required to send a message

The workaround for that is move the condition to the place where you are making the call to FooMailer.bar_email.deliver!

    • #rails
    • #rails3
    • #actionmailer
    • #error
    • #ArgumentError
  • 6 months ago
  • 6
  • Comments
  • Permalink
  • Share
    Tweet

6 Notes/ Hide

  1. gemfury liked this
  2. edgar posted this

Recent comments

Blog comments powered by Disqus
← Previous • Next →

Portrait/Logo

About

When I'm not spending time with Jessica and my kids, I build web applications. Rails developer, believer of Agile Development and Lean startups. NoSQL enthusiast.
CTO and Lord of the API at Piictu

Me, Elsewhere

  • @edgar on Twitter
  • Facebook Profile
  • edgargonzaleznetve on Youtube
  • egg on Flickr
  • edgar on Foursquare
  • My Skype Info
  • Linkedin Profile
  • edgar on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr