0

I want to use Mailjet in order to send order confirmation email.

First of all, I installed Gem and configure as Mailjet guide

gem 'mailjet'

initializers/mailjet.rb

Mailjet.configure do |config|
  config.api_key = '<my_api_key>'
  config.secret_key = '<my_secret_key>'
  config.default_from = '<my_email>'
end

config/application.rb

config.action_mailer.delivery_method = :mailjet_api

And this is action in my controller

def send_email_reserved
    email = { :from_email   => "<my_from_email>",
          :from_name    => "Dona Sky",
          :subject      => "Hello",
          :text_part    => "Hi",
          :recipients   => [{:email => "<my_to_email>"}] }

    test = Mailjet::Send.create(email)
    p test.attributes['Sent']
  end

When I called the action, it showed the error

NoMethodError: undefined method `[]' for #<Set: {#<MIME::Type: application/json>}>
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:307:in `type_for_extension'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:312:in `type_for_extension'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block (2 levels) in stringify_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `map'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block in stringify_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `each'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `inject'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `stringify_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:92:in `make_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:58:in `initialize'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:67:in `handle_api_call'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:47:in `post'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/resource.rb:215:in `save'
Leo Le
  • 815
  • 3
  • 13
  • 33

1 Answers1

1

This is a dependency issue. Try adding this : gem rest-client '~>1.6.9' to your Gemfile and run bundle update

Guillaume Badi
  • 749
  • 5
  • 15