简体   繁体   English

如何在 Rails 中使用 Mailgun 和 HTTParty

[英]How to use Mailgun with HTTParty in Rails

I want to use Mailgun with HTTParty in Rails:我想在 Rails 中将 Mailgun 与 HTTParty 结合使用:

RestClient.post "https://api:key-###"\
    "@api.mailgun.net/v3/###/messages",
    from: from_email,
    to: to_email,
    subject: title,
    html: body_text

It's working but它的工作,但

payload = {
    from: email_history.from_email,
    to: email_history.to_email,
    subject: email_history.title,
    html: email_history.body_text,
    multipart: true
}

response = SendEmailJob.post('https://api:key-###'\
'@api.mailgun.net/v3/###/messages', payload)

Returns:退货:

{
  "message": "'from' parameter is missing"
}

I checked and the payload "from" parameter exists.我检查过,有效负载“from”参数存在。

How can I fix this?我怎样才能解决这个问题?

I solved this by adding the body:我通过添加正文解决了这个问题:

SendEmailJob.post('api:key-###'\ '@api.mailgun.net/v3/###/messages', body: payload)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM