sendHttpPostRequest error message

I’m getting crazy in trying to simply send a mail.

The email binding doesn’t work with some error message. Then I thought “hey with sendgrid I can also send a mail via a http request - easy”. But also that sendHttpPostRequest doesn’t work.

This is my rule:

rule "Presence"
when
    Item SWITCH_PRESENCE changed
then
    val content = '{"personalizations": [{"to": [{"email": "me@mail.xyz"}]}],"from": {"email": "me@mail.xyz"},"subject": "Philipp changed","content": [{"type": "text/plain", "value": "presence changed"}]}'
    val headers = newHashMap("Authorization" -> "Bearer SomeBearerToken")
    sendHttpPostRequest("https://api.sendgrid.com/v3/mail/send", "application/json", content, headers, 3000)
end

This fails with this error message:

    2020-04-07 21:00:38.327 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Presence': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.HTTP.sendHttpPostRequest(java.lang.String,java.lang.String,java.lang.String,int) on instance: null

This really drives me crazy. I’m struggeling with a simple mail send for hours now. Any ideas why it doesn’t work?

The code is exactly like in the documentation: https://www.openhab.org/docs/configuration/actions.html#http-actions

See

and

The change to add headers didn’t make it into 2.5.x. See this thread. You can get a jar file that has the change, but I’ve yet to make it work. I’m going to give it another try soon. Note that the thread I mention is talking about jython, but I’m pretty sure this applies in general. Could be wrong though.

Ah okay - thanks. So probably I’ll executeCommandline() a curl.

It is the java action HTTP so it works on jython and RulesDSL.