global_merge_vars doesn't work
Closed this issue · 3 comments
rubydev commented
Hello,
my code looks like this:
class RemindersMailer < ActionMailer::Base def feedback_email mail( to: 'name@domain.com', body: '', subject: 'Your feedback is important to us!', template: 'your-feedback-is-important-to-us', global_merge_vars: [ { 'name' => 'FNAME', 'content' => 'Jamie' }, { 'name' => 'CONSULTANT_NAME', 'content' => 'Grace' } ] ) end end
RemindersMailer.feedback_email.deliver_now
But "global_merge_vars" are in header instead in message. So vars aren't replaced. Could you help me? Request looks like this:
"template_name": "your-feedback-is-important-to-us", "template_content": null, "message": { "auto_html": null, "auto_text": null, "bcc_address": null, "from_email": "info@domain.com", "from_name": null, "global_merge_vars": null, "headers": { "Date": "Mon, 18 Dec 2017 17:32:32 +0100", "From": "info@domain.com", "To": [ "name@domain.com" ], "Bcc": "info@domain.com", "Message-ID": "<5a37eda0553ad_bf7@XYZ-MacBook-Pro.local.mail>", "Subject": "Your feedback is important to us!", "Mime-Version": "1.0", "Content-Type": "text/plain", "Content-Transfer-Encoding": "7bit", "template": "your-feedback-is-important-to-us", "global-merge-vars": "{\"name\"=>\"FNAME\", \"content\"=>\"Jamie\"}, {\"name\"=>\"CONSULTANT_NAME\", \"content\"=>\"Grace\"}" }, "html": null, "important": false, "inline_css": null, "merge": null, "merge_language": null, "merge_vars": null, "metadata": null, "preserve_recipients": null, "return_path_domain": null, "signing_domain": null, "subaccount": null, "subject": "Your feedback is important to us!", "tags": {}, "text": "", "to": [ { "email": "name@domain.com", "name": null, "type": "to" }, { "email": "info@domain.com", "name": null, "type": "bcc" } ], "track_clicks": null, "track_opens": null, "tracking_domain": null, "url_strip_qs": null, "view_content_link": null }, "async": false, "ip_pool": null, "send_at": null, "key": "xyz" }
mandrill_dm 1.3.4 rails 5.1.4 mail 2.7.0 mandrill-api 1.0.53
Maybe I'm using it in wrong way? Could you help me?
rubydev commented
With gem mail version 2.6.4 it is working well, with 2.7.0 no.
Tensho commented
Yes, there is breaking change of the private API in mail
2.7.0. As far as mandrill_dm
relies on private API for retrieving header value unmodified, it should be updated accordingly.
>> require 'mail'
true
>> Mail::VERSION.version
"2.7.0"
>> m = Mail.new
#<Mail::Message:70160019869900, Multipart: false, Headers: >
>> m[:global_merge_vars] = {
'name' => 'FNAME',
'content' => 'Jamie'
}
{
"name" => "FNAME",
"content" => "Jamie"
}
>> m[:global_merge_vars].instance_variable_get(:@value)
nil # Should be initial value according to mail 2.6.4
>> m[:global_merge_vars].instance_variable_get(:@unparsed_value)
{
"name" => "FNAME",
"content" => "Jamie"
}
>> m[:global_merge_vars].value
"{\"name\"=>\"FNAME\", \"content\"=>\"Jamie\"}" # Still returns encoded value
Compare #field
method in version 2.7.0 and 2.6.4. You may notice that the raw value is no more assigned to @value
. But mandrill_dm
relies on it in the #get_value
method.