1

I am trying to do a post request and send a message with mailgun API, but I can't seem to figure out how to format the message data in swift. Having issues with from parameter in the data I am uploading.

request.setValue("Basic \(base64Credentials)", forHTTPHeaderField: "Authorization")
        request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

    let data = "from: Foo <info@sandbox(sandboxInfo).mailgun.org>&to: <foo@me.com>&subject:Hello&text:Testing Mailgun"
        request.httpBody = data.data(using: String.Encoding.ascii)

Respone:

);
    "Cache-Control" =     (
        "no-store"
    );
    Connection =     (
        "keep-alive"
    );
    "Content-Length" =     (
        46
    );
    "Content-Type" =     (
        "application/json"
    );
    Date =     (
        "Wed, 03 Mar 2021 01:05:39 GMT"
    );
    Server =     (
        nginx
    );
} }
response code = 400
data {
  "message": "'from' parameter is missing"
}
Iam Wayne
  • 561
  • 6
  • 26
  • Help yourself by finding out what the HTTP status code of 400 means. – El Tomato Mar 03 '21 at 06:59
  • 2
    I know what the code means, it tells me the error in the response message. That the *from parameter is misisng*, but I don't know what's the correct parameter. – Iam Wayne Mar 03 '21 at 13:30
  • You have to submit all needed parameters and set up MG correct. This complete example (including vb,net code) may help you: https://stackoverflow.com/questions/68150905/can-i-send-email-with-mailgun-sandbox-domain-under-my-local-os/68542876#68542876 – FredyWenger Jul 27 '21 at 10:22

1 Answers1

-1

I have been trying to access this API from mailgun, it seems the documentation is a bit misleading. when using https://api.mailgun.net/v3/xxxxx.domain/messages it seems that the body should be in a form of params for the API to recognize it.

Jtaw Cañada
  • 147
  • 1
  • 7