couldn't send mail from mandrill in ruby on rails

158 Views Asked by At

Hello I am newbie to ruby on rails, I am trying to send mail from mandrill and following this documentation https://mailchimp.com/developer/transactional/guides/send-first-email/ but somehow I am getting this error

Error: {:status=>500, :response_body=>"{\"status\":\"error\",\"code\":-1,\"name\":\"ValidationError\",\"message\":\"You must specify a message value\"}"}

here is my code

client = MailchimpTransactional::Client.new('xxxxxxxxxRWX-nA')
message = {
  from_email: "[email protected]",
  subject: "Hello world",
  text: "Welcome to Mailchimp Transactional!",
  to: [
    {
      email: "[email protected]",
      type: "to"
    }
  ]
}

begin
  response = client.messages.send(message)
  p response
rescue MailchimpTransactional::ApiError => e
  puts "Error: #{e}"
end
1

There are 1 best solutions below

0
Bibek Shrestha On BEST ANSWER

That's because you have to pass it to the client with a key value of message as follows:

This is incorrect:

response = client.messages.send(message)

This is correct:

response = client.messages.send(message: message)

The transactional email documentation on Mailchimp's website is incorrect.