Comments (11)
I feel like this could be related to #12.
from mailgun-ruby.
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" => ["[email protected]"],
"subject" => ["Merge Fields Test"],
"text" => ["Hello %recipient.first%, this is a test. Your full name is %recipient.first% %last%."],
"to" => ["'John Doe' <[email protected]>", "'Jane Doe' <[email protected]>"],
"recipient-variables" => [ {"[email protected]" => {"id" => nil},
"[email protected]" => {"first" => "John", "last" => "Doe"},
"[email protected]" => {"first" => "Jane", "last" => "Doe"}
]
}
response = http_client["mail.domain.com/messages"].post(data)
from mailgun-ruby.
Well this is interesting: The API documentation shows that
POST /<domain>/messages
does not accept a recipient-variables
parameter.
from mailgun-ruby.
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" => ["[email protected]"],
"subject" => ["Merge Fields Test"],
"text" => ["Hello %recipient.first%, this is a test. Your full name is %recipient.first% %last%."],
"to" => ["'John Doe' <[email protected]>", "'Jane Doe' <[email protected]>"],
"recipient-variables" => {"[email protected]" => {"id" => nil},
"[email protected]" => {"first" => "John", "last" => "Doe"},
"[email protected]" => {"first" => "Jane", "last" => "Doe"}
}.to_json
}
response = http_client["mail.domain.com/messages"].post(data)
Mainly I made sure that the recipient-variables
was JSON (not a Hash) and it was outside the parent array.
from mailgun-ruby.
I've added some code to the send_message
method that seems to eliminate the problem. I'm not sure if this is the best way to solve it, but the issue is that the recipient-variables
are inside an array.
mailgun-ruby/lib/mailgun/messages/batch_message.rb
:
...
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 batch_message.rb
from mailgun-ruby.
I've opened PR #23.
from mailgun-ruby.
👍 I'll review this soon! Thanks for the details.
from mailgun-ruby.
Thanks! For what it's worth, I've dug a little deeper and I've found that both simple_setter
and complex_setter
will set variables inside of arrays. It looks like that might be part of the problem, since recipient-variables
can't be inside an array.
from mailgun-ruby.
Is there a workaround for this or an ETA for the pull request to be accepted?
from mailgun-ruby.
This has been merged. Cutting a new Gem in an hour or so. Thanks for your work on this!
from mailgun-ruby.
Works now. Thank you.
from mailgun-ruby.
Related Issues (20)
- TypeError: no implicit conversion of nil into String HOT 1
- Use multiple domains with different sending keys HOT 4
- Is there a way to handle different recipient variables with same email HOT 1
- The delete_bounce method requires email addresses to be escaped. HOT 2
- NoMethodError (undefined method 'proxy_url' for Mailgun:Module) HOT 2
- Error api_host after update to 1.2.7 HOT 2
- TypeError (no implicit conversion of nil into String) HOT 5
- Primitive types are serialized twice to JSON HOT 1
- Abandoned dependency: rest-client abandoned in 2019 HOT 7
- mailgun-ruby 1.2.9 not on rubygems HOT 1
- Response object can be nil HOT 2
- Getting error : NameError: uninitialized constant MailgunRetriesCron HOT 2
- delete_if returning true from function when encountering a nil value HOT 3
- Follow up error while processing response of an unauthorized request
- single-verification HOT 1
- Next page HOT 1
- Headers are always downcased when using Railgun HOT 1
- events abstraction issues
- Missing docs for Templates
- Remove `OpenStruct` usage, will warn in Ruby 3.4, raise in Ruby 3.5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailgun-ruby.