Closed kshnurov closed 8 years ago
@kshnurov Yep, agreed. For my use case, I only needed merge
because I'm using the standard merge tags, so this scratched my itch. But full merge_vars
support would be great.
*|FNAME|*
*|LNAME|*
*|EMAIL|*
*|DATE:FORMAT|*
*|CURRENT_YEAR|*
+1
Sorry, didn't get it from the conversation you pointed out. I don't seem to be able to use 'merge_vars' option. Could you please clarify how to provide custom data to mandrill api?
merge
but as far as I see not merge_vars
.I needed it too so looked into how to do it but so far I've only come up with a hack:
In MandrillDm::Message
, add:
def merge_vars
return unless mail[:merge_vars] and mail[:merge_vars].value
eval mail[:merge_vars].value
end
plus merge_vars: merge_vars,
in to_json
.
Then you can pass the merge variables using the format described here: https://mandrill.zendesk.com/hc/en-us/articles/205582487-How-to-Use-Merge-Tags-to-Add-Dynamic-Content
In my mailer, I add headers[:merge_vars] = [{ rcpt: "email", vars: [] }].to_s
. The reason for to_s
is because mail[:merge_vars].value
will somehow not return the square brackets. eval
is used to transform the string into an array again.
That's all super hacky, I don't know if anyone has a better idea on how to solve this.
I pushed the code here: https://github.com/blarralde/mandrill_dm/blob/master/lib/mandrill_dm/message.rb
That's pretty the same what I did. Though I pass only 'vars' (from { rcpt: "email", vars: [] }
) two-dimensional array (as I send to multiple recipients) and map it to the format needed in the dm itself.
It's hacky, indeed, but I don't see any other ways yet.
@Sysqa I guess this can be closed now? PR #22
feature has been added, closing.
@spovich would be great if we could have new version of the gem with this feature available
@tomasc yes, I was thinking the same. I was hoping the backlog of PR's would settle down but that may be a while yet. @kshnurov what do you think about a new release?
@spovich yeah, let's finish with #38 and #39 and release a new version.
merge_vars
andglobal_merge_vars
will allow to send customized messages to each recipient.