On 10 Aug 2011, at 16:35, Adam O'Connor wrote:
> I'm stuck on something 'simple' - custom mail header. Seems this
> should work but can't get it to come out correctly. Any help
> appreciated:
>
> http://pastie.org/private/skedkstanvm8hpzr8ounia
In your call to #mail:
mail(:to => '[email protected]',
:from => email,
:subject => "Message from the site",
:headers['X-SMTPAPI'] => "{\"category\" : \"Drip Email\"}"
)
you're passing a hash of headers to the #mail method, and one of your keys is
:headers['X-SMTPAPI']. Ruby tries to execute this as calling the #[] method on
the symbol :headers, which returns nil (under ActiveSupport).
This all happens before the #mail method gets a chance to see it; in other
words, your method call looks like this:
mail(:to => '[email protected]',
:from => email,
:subject => "Message from the site",
nil => "{\"category\" : \"Drip Email\"}"
)
That's why you're seeing the {"category" : "Drip Email"} value appear in your
email, but with an empty name for the header.
To set a header value, you can either specify it directly in the hash you pass
to #mail:
mail(:to => '[email protected]',
:from => email,
:subject => "Message from the site",
'X-SMTPAPI' => "{\"category\" : \"Drip Email\"}"
)
or you can use the #headers method separately:
headers['X-SMTPAPI'] = "{\"category\" : \"Drip Email\"}"
mail(:to => '[email protected]',
:from => email,
:subject => "Message from the site"
)
Chris
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.