Hi,

There's a very popular question on Stack Overflow - how to specify a sender 
in a "MyCompany <[email protected]>" format 
<http://stackoverflow.com/questions/957422/rails-actionmailer-format-sender-and-recipient-name-email-address>?
 
Well, the answer is to specify it exactly like that, no brainer. However, 
the accepted answer (91 votes) suggests this: @recipients   = 
"\"#{user.name}\" <#{user.email}>". This is totally wrong. A better answer 
(150 votes) suggests this: 

require 'mail'
address = Mail::Address.new user.email
address.display_name = user.name
address.format

This is the right answer - but it doesn't feel the Rails way of doing 
things. In ERB/Slim templates, we say <%= user.email %> or = user.email, 
and we know everything will be escaped and not interpreted as HTML. I think 
ActionMailer could also take care about e-mail escaping. Example:

# Before:
class BillingMailer < ApplicationMailer
  require 'mail'
  address = Mail::Address.new "billing@#{Setting.panel_domain}"
  address.display_name = "#{Setting.title} Billing"

  default template_path: 'mailers/billing',
    from: address.format

# After:  
class BillingMailer < ApplicationMailer
  default template_path: 'mailers/billing',
    from_name: "#{Setting.title} Billing",
    from_email: "billing@#{Setting.panel_domain}"


Does it make sense? Is it something that Rails community would find useful? 
Would this be accepted to Rails if I contributed the code?

Many thanks,
-Damian Nowak

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to