Giter VIP home page Giter VIP logo

Comments (11)

mide avatar mide commented on July 29, 2024

I feel like this could be related to #12.

from mailgun-ruby.

mide avatar mide commented on July 29, 2024

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.

mide avatar mide commented on July 29, 2024

Well this is interesting: The API documentation shows that

POST /<domain>/messages

does not accept a recipient-variables parameter.

from mailgun-ruby.

mide avatar mide commented on July 29, 2024

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.

mide avatar mide commented on July 29, 2024

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.

mide avatar mide commented on July 29, 2024

I've opened PR #23.

from mailgun-ruby.

travelton avatar travelton commented on July 29, 2024

👍 I'll review this soon! Thanks for the details.

from mailgun-ruby.

mide avatar mide commented on July 29, 2024

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.

erm213 avatar erm213 commented on July 29, 2024

Is there a workaround for this or an ETA for the pull request to be accepted?

from mailgun-ruby.

travelton avatar travelton commented on July 29, 2024

This has been merged. Cutting a new Gem in an hour or so. Thanks for your work on this!

from mailgun-ruby.

erm213 avatar erm213 commented on July 29, 2024

Works now. Thank you.

from mailgun-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.