无法从ruby on rails中发送邮件

dwthyt8l  于 2023-04-29  发布在  Ruby
关注(0)|答案(1)|浏览(116)

你好,我是ruby on rails的新手,我试图从mandrill发送邮件,并遵循此文档https://mailchimp.com/developer/transactional/guides/send-first-email/,但不知何故,我得到了这个错误

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

这是我的代码

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

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

kyks70gy1#

这是因为您必须将其传递给客户端,其键值为message,如下所示:
这是不正确的:

response = client.messages.send(message)

这是正确的:

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

Mailchimp网站上的交易电子邮件文档不正确。

相关问题