-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge Fields not Working #22
Comments
I feel like this could be related to #12. |
I've traced the Gem's flow to the following code, with the problem still happening. I'm still working on finding the root cause. http_client = RestClient::Resource.new("https://api.mailgun.net/v2",
:user => "api",
:password => "[MAILGUN KEY]",
:user_agent => "mailgun-sdk-ruby/1.0.2")
data = {"from" => ["system@mail.domain.com"],
"subject" => ["Merge Fields Test"],
"text" => ["Hello %recipient.first%, this is a test. Your full name is %recipient.first% %last%."],
"to" => ["'John Doe' <john.doe@gmail.com>", "'Jane Doe' <jane.doe@gmail.com>"],
"recipient-variables" => [ {"system@mail.domain.com" => {"id" => nil},
"john.doe@gmail.com" => {"first" => "John", "last" => "Doe"},
"jane.doe@gmail.com" => {"first" => "Jane", "last" => "Doe"}
]
}
response = http_client["mail.domain.com/messages"].post(data) |
Well this is interesting: The API documentation shows that
does not accept a |
Alright, I've figured out the following works: http_client = RestClient::Resource.new("https://api.mailgun.net/v2",
:user => "api",
:password => "[MAILGUN KEY]",
:user_agent => "mailgun-sdk-ruby/1.0.2")
data = {"from" => ["system@mail.domain.com"],
"subject" => ["Merge Fields Test"],
"text" => ["Hello %recipient.first%, this is a test. Your full name is %recipient.first% %last%."],
"to" => ["'John Doe' <john.doe@gmail.com>", "'Jane Doe' <jane.doe@gmail.com>"],
"recipient-variables" => {"system@mail.domain.com" => {"id" => nil},
"john.doe@gmail.com" => {"first" => "John", "last" => "Doe"},
"jane.doe@gmail.com" => {"first" => "Jane", "last" => "Doe"}
}.to_json
}
response = http_client["mail.domain.com/messages"].post(data) Mainly I made sure that the |
I've added some code to the
...
def send_message(message)
simple_setter("recipient-variables", JSON.generate(@recipient_variables))
if @message.has_key?("recipient-variables")
@message["recipient-variables"] = @message["recipient-variables"].first
end
response = @client.send_message(@domain, @message).to_h!
message_id = response['id'].gsub(/\>|\</, '')
@message_ids[message_id] = count_recipients()
reset_message()
end
... Edit: I've moved the code into |
I've opened PR #23. |
👍 I'll review this soon! Thanks for the details. |
Thanks! For what it's worth, I've dug a little deeper and I've found that both |
Is there a workaround for this or an ETA for the pull request to be accepted? |
This has been merged. Cutting a new Gem in an hour or so. Thanks for your work on this! |
Works now. Thank you. |
I'm trying to send emails through the mailgun-ruby gem, and it doesn't seem to be merging the fields when sent.
I've been able to reproduce the problem with the following code:
Each recipient is getting the non-merged emails with all recipients in the "to" address.
The text was updated successfully, but these errors were encountered: