I am trying to invoke mailgun send message api. The following code works if I pass the params along with url -
String targetUrl = "https://api.mailgun.net/v2/my_domain_name/messages?from=fromAddress&to=toAddress&subject=sub&text=random+message"
But when I try to add these params in the body then it does not work. I keep getting bad request from mailgun. -
String targetUrl = "https://api.mailgun.net/v2/my_domain_name/messages
body = [from:"fromAddress", to:"toAddress", subject:"sub", text:"random message"]
Here is the full code -
def sendEmail(String mailBody, String sub, String toIds) {
String targetUrl = "https://api.mailgun.net/v2/my_domain_name/messages"
def http = new HTTPBuilder(targetUrl)
http.request( groovyx.net.http.Method.POST, groovyx.net.http.ContentType.JSON) {
body = [from:"fromAddress", to:"toAddress", subject:"sub", text:"random message"]
headers = ['Authorization':"Basic " + "api:my_api_key".bytes.encodeBase64().toString()]
response.success = { resp, reader ->
println "valid response: " + reader
}
}
}
Thanks!