Search code examples
ruby-on-railsrubymailgunrest-clienthttparty

How to use Mailgun with HTTParty in Rails


I want to use Mailgun with HTTParty in Rails:

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.

How can I fix this?


Solution

  • I solved this by adding the body:

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