Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6377595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:53:38+00:00 2026-05-25T01:53:38+00:00

I have a problem. My mailer sends the same e-mail 4 times. I’m pretty

  • 0

I have a problem. My mailer sends the same e-mail 4 times. I’m pretty sure I only call it once though. What could be the reason?

Running Rails 3.0.7 on Ruby 1.9.2 and Unicorn, if that matters.

Here is the mailer:

class NotificationMailer < ActionMailer::Base
  default :from => "herald@artistsnclients.com"

  def order_new(user, order)
    @user = user
    @order = order
    mail( :to => "#{user.name} <#{user.email}>", :subject => "You have one new order to review (##{order.id})" )
  end
end

What calls the mailer is a callback in the model Notification:

class Notification < ActiveRecord::Base
  attr_accessible :read, :user_id, :happening_type, :happening_id, :happening_status

  enum_attr :happening_status, %w(new approved rejected cancelled payed completed accepted new_post)

  belongs_to :user
  belongs_to :happening, :polymorphic => true

  after_create :send_email

  private

  def send_email
    # Send e-mail here
    if [:new, :approved, :rejected, :cancelled, :payed, :completed, :accepted].include? self.happening_status
      right_mailer = NotificationMailer.method("order_#{self.happening_status}".to_sym)
      right_mailer.call(self.user, self.happening).deliver
    elsif [:new_post].include? self.happening_status
      NotificationMailer.note_new(self.user, self.happening).deliver
    end
  end
end

The Notification object is created from a callback in the Note model:

class Note < ActiveRecord::Base
  ...
  after_create :notify_artist

  private

  def notify_artist
    self.notifications.create :read => false, :happening_status => :new, :user_id => self.artist_id
  end
end

Also, here is the part of the log that belongs to the controller from which the Notification model is created:

Started POST "/notes" for 178.8.127.86 at 2011-07-15 18:03:45 +0000
  Processing by NotesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"8UhgV74SUZibcrowriqQZAketiALnkpHMhu0bkuZ4VQ=", "note"=>{"content"=>"Okaaay, *will do*", "order_id"=>"1"}, "commit"=>"Reply"}
  [1m[36mUser Load (0.1ms)[0m  [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m
  [1m[35mSQL (0.1ms)[0m  BEGIN
  [1m[36mSQL (0.5ms)[0m  [1mdescribe `notes`[0m
  [1m[35mAREL (0.3ms)[0m  INSERT INTO `notes` (`user_id`, `order_id`, `content`, `created_at`, `updated_at`) VALUES (1, 1, 'Okaaay, *will do*', '2011-07-15 18:03:45', '2011-07-15 18:03:45')
  [1m[36mOrder Load (0.1ms)[0m  [1mSELECT `orders`.* FROM `orders` WHERE `orders`.`id` = 1 LIMIT 1[0m
  [1m[35mNotification Load (0.5ms)[0m  SELECT `notifications`.* FROM `notifications` WHERE (`notifications`.happening_id = 12 AND `notifications`.happening_type = 'Note') LIMIT 1
  [1m[36mSQL (0.9ms)[0m  [1mdescribe `notifications`[0m
  [1m[35mAREL (0.3ms)[0m  INSERT INTO `notifications` (`read`, `user_id`, `happening_id`, `happening_type`, `created_at`, `updated_at`, `happening_status`) VALUES (0, 2, 12, 'Note', '2011-07-15 18:03:45', '2011-07-15 18:03:45', 'new_post')
  [1m[36mUser Load (0.2ms)[0m  [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1[0m
  [1m[35mNote Load (0.3ms)[0m  SELECT `notes`.* FROM `notes` WHERE `notes`.`id` = 12 LIMIT 1
Rendered notification_mailer/note_new.html.haml (3.6ms)

Sent mail to [MY E-MAIL] (2362ms)
Date: Fri, 15 Jul 2011 18:03:46 +0000
From: herald@artistsnclients.com
To: Dummy <[MY E-MAIL]>
Message-ID: <4e208102724f_55c11225a4584d7@artistsnclients.mail>
Subject: New message in order #1
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello Dummy,</p>
<p>There is a new message in your order #1.</p>
<blockquote>
  Okaaay, *will do*
</blockquote>
<hr>
<p>
  With lots and lots of love,
  <br>
  Artists&amp;Clients Staff
</p>
  [1m[36mSQL (564.1ms)[0m  [1mCOMMIT[0m
Redirected to http://dev.artistsnclients.com/orders/1
Completed 302 Found in 3623ms
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:53:39+00:00Added an answer on May 25, 2026 at 1:53 am

    Please try newer version of the gem named 0.9.8, I think we managed to fix that bug:

    https://rubygems.org/gems/postmark

    Let me know if it helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PEAR's Mail package to send email from my script. I'm pretty sure
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.
I have a problem using the Java search function in Eclipse on a particular
I have a problem with a little .Net web application which uses the Amazon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.