ActionMailer after_filter violates content_type

[Rails 3.2.13] I have an email program that sends implicit multi-page emails based on .text.erband templates .html.haml. No problems.

I am trying to add after_filter to conditionally prevent the sending of invalid email messages. Based on this answer and all the documentation I read, it looks pretty simple.

However, including this option after_filter change the type of content on multipart/alternativeto text/plain, even if the letter really . In the documents: "Implicit template conversion is not performed if attachments or parts are added to the letter." Is it applicable here? Is this the expected behavior, or am I doing something wrong?

Holding his head against the wall, because it seems so simple.

class Notify < ActionMailer::Base

  include AbstractController::Callbacks

  after_filter :ensure_valid

  def some_email(user_id)
    @user = User.find(user_id)
    mail(to: @user.email)
  end

  ...

  private

  def ensure_valid
    if User.where(email: mail.to, invalid_email: true).any?
      mail.perform_deliveries = false
    end
    true
  end

end

Edit : after more complicated work, it seems that the call to the mailobject in general in after_filter is turned off by many-part, even with something like:

def ensure_valid
  puts "mail: #{mail}"
  true
end

What's going on here?


I tried adding content_type + params back manually to the after_filter file, for example

mail.content_type = 'multipart/alternative'
mail.header['Content-Type'].parameters[:boundary] = mail.body.boundary
mail.header['Content-Type'].parameters[:charset] = 'UTF-8' 

But for some reason this does not seem to work. It sets content_type if I include only

mail.content_type = 'multipart/alternative'

.. .

, , :

  • content_type environment.rb
  • content_type
+3
1

, , , , message mail after_filter :

def ensure_valid
  if User.where(email: message.to, invalid_email: true).any?
    message.perform_deliveries = false
  end
  true
end

perform_deliveries , content_type ( multipart/alternative). , mail message.

+2

All Articles