we used to use Clickatell which is an international SMS Gateway. Here is a copy-paste of the code we used, hopefully it is still working. You need to install HTTPBuilder in Grails and setup a Clickatell account to fill in the ??????.
def sendClickatellSms(def number, def text) {
def http = new HTTPBuilder('http://api.clickatell.com/')
http.contentType = TEXT
EncoderRegistry encoders = new EncoderRegistry();
encoders.setCharset('ISO-8859-1')
http.setEncoderRegistry(encoders)
http.request( POST ) {
uri.path = 'http/sendmsg'
requestContentType = URLENC
if (number.substring(0, 1) == '+') {
// Remove a leading plus sign
number = number.substring(1)
}
body = [ api_id: '??????', user: '??????', password: '??????', from: '??????', to: number, text: text, concat: '3', callback: '2', deliv_ack: '1' ]
response.success = { resp, reader ->
def msg = reader.text
if (msg.substring(0, 2) == 'ID') {
return 0
} else if (msg.substring(0, 3) == 'ERR') {
log.error("Clickatell " + msg)
return msg.substring(5, 8).toInteger()
} else {
return 1
}
}
response.failure = { resp ->
log.error("Failed to contact Clickatell: ${resp.statusLine}")
return 1
}
}
}