[Rails] ActionMailer - ROR Recipes - Multipart/alternative - How to make it work.

softwareengineer 99 softwareengineer99 at yahoo.com
Tue Feb 7 19:04:39 GMT 2006


Dear Chad,
  
  Thank you for your assistance.
  
  I tried renaming as per your suggestion and tried resending email but the email delivery failed.
  
  Then I looked in the localization code and found the following code in  lib/localization.rb which is responsible for adding the _en to the  template name:
  
    # redefinition of ActionMail::Base#render_message, that adds locale suffix to
    # the template name
    ActionMailer::Base.module_eval <<-EOL
    private
    def render_message(method_name, body)
      initialize_template_class(body).render_file(method_name + "_#{CONFIG[:default_language]}")
    end
    EOL
  
  I commented the entire code out, restarted the server and tried again and voila!, it worked.
  
  My forgot password message arrived with content-type set to:
  
  multipart/alternative; boundary=mimepart_43e8db39b433c_1a4a..fdbaf1bcc3c9

  Seeing how many folks are using SLHG, I highly recommend the addition  of following tips as the addition of these will highly benefit your  readers:
  
  1. How to modify the above code to keep the localization but still be able to use multi-part messages.
  2. How to specify a reply_to address for ActionMailer. (I still cannot figure it out)
  3. How to specify content type of text/html without using multipart for SLHG (by using @content_type="text/html")
  
  The SLHG works great, though it does takes some time. I have finally  integrated it and recommend that it be added to the recipes also. The  documentation that comes with SLHG is pretty self explanatory but can  be overwhelming.
  
  What editor did you use to compose the book? Docbook or something else?
  
  Thank you once again for your assistance and great tips.
  
  Frank
  Ruby Gemologist
  P.S. I recommend that all Ruby developers be officially called Ruby gemologists to stand out from the rest.
  
  
  
Chad Fowler <chadfowler at gmail.com> wrote:  On 2/7/06, Ben Munat  wrote:
> Chad Fowler wrote:
> > Would this work if your templates weren't called "_en"?  I believe
> > ActionMailer requires the template to be named _exactly_ the same as the
> > mailer's method (forgot_password) with the remaining dot-separated parts
> > of the name representing the mime type and template type (eg .rhtml).
> >
> > So if you rename your templates to, for example,
> > forgot_password.text.plain.rhtml does your mailer start working again?
> >
>
> I used SHLG and it generated a "forgot_password" method in my MemberNotify ActionMailer
> subclass and a "forgot_password_en.html" view. That all appears to work.
>
> Sorry I can't offer any insight on why things aren't working -- I'm still very new to all
> this -- but I thought I should point out that the "_en" isn't breaking mine. I'm fairly
> certain that's added by the Localization plugin.

Yea, my bet is (I don't know the localization plugin well) that the
localization plugin overrides the view-finding logic in a way that
doesn't affect the hardcoded checks that happen in the ActionMailer
code.  It might be worth a patch to ActionMailer to make it more
flexible if that's the case (or maybe not).

--
Chad Fowler
http://chadfowler.com
http://pragmaticprogrammer.com/titles/fr_rr/ (Rails Recipes - In Beta!)
http://pragmaticprogrammer.com/titles/mjwti/ (My Job Went to India,
and All I Got Was This Lousy Book)
http://rubycentral.org
http://rubygarden.org
http://rubygems.rubyforge.org (over one million gems served!)
_______________________________________________
Rails mailing list
Rails at lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails


		
---------------------------------
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060207/e36abd29/attachment-0001.html


More information about the Rails mailing list