[mail] Improve action documentation ()

* Use of actions.get instead of getActions 

Adopt doc to newest default JS environment regarding calling mail actions via actions.get

Signed-off-by: Siegmar Immel <36704892+SiggiFR@users.noreply.github.com>

* [mail] Adding Javascript examples in documentation

Because function name has changed to get actions defined within the mail binding, the examples have been extended by a tab for JavaScript code.

* Update bundles/org.openhab.binding.mail/README.md

Co-authored-by: J-N-K <github@klug.nrw>
Signed-off-by: Siegmar Immel <36704892+SiggiFR@users.noreply.github.com>

---------

Signed-off-by: Siegmar Immel <36704892+SiggiFR@users.noreply.github.com>
Co-authored-by: J-N-K <github@klug.nrw>
This commit is contained in:
Siegmar Immel 2023-11-28 22:45:26 +01:00 committed by GitHub
parent f4aa1c6d59
commit 6df602599e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -130,7 +130,7 @@ Both functions return a boolean as the result of the operation.
`recipient` can be a single address (`mail@example.com`) or a list of addresses, concatenated by a comma (`mail@example.com, mail2@example.com`).
Since there is a separate rule action instance for each `smtp` thing, this needs to be retrieved through `getActions(scope, thingUID)`.
Since there is a separate rule action instance for each `smtp` thing, this needs to be retrieved through `getActions(scope, thingUID)` (DSL) or `actions.get(scope, thingUID)` (Javascript).
The first parameter always has to be `mail` and the second is the full Thing UID of the SMTP server that should be used.
Once this action instance is retrieved, you can invoke the action method on it.
@ -139,6 +139,10 @@ Using different character sets may produce unwanted results.
Examples:
:::: tabs
::: tab DSL
```java
val mailActions = getActions("mail","mail:smtp:samplesmtp")
val success = mailActions.sendMail("mail@example.com", "Test subject", "This is the mail content.")
@ -155,7 +159,30 @@ val List<String> attachmentUrlList = newArrayList(
val mailActions = getActions("mail","mail:smtp:sampleserver")
mailActions.sendHtmlMailWithAttachments("mail@example.com", "Test subject", "<h1>Header</h1>This is the mail content.", attachmentUrlList)
```
:::
::: tab JavaScript
```javascript
val mailActions = actions.get("mail","mail:smtp:samplesmtp")
val success = mailActions.sendMail("mail@example.com", "Test subject", "This is the mail content.")
success = mailActions.sendMail("mail1@example.com, mail2@example.com", "Test subject", "This is the mail content sent to multiple recipients.")
```
```javascript
import java.util.List
val List<String> attachmentUrlList = newArrayList(
"http://some.web/site/snap.jpg&param=value",
"file:///tmp/201601011031.jpg")
val mailActions = actions.get("mail","mail:smtp:sampleserver")
mailActions.sendHtmlMailWithAttachments("mail@example.com", "Test subject", "<h1>Header</h1>This is the mail content.", attachmentUrlList)
```
:::
::::
## Mail Headers
The binding allows one to add custom e-mail headers to messages that it sends.
@ -163,6 +190,11 @@ For example if you want e-mails sent by this binding to be grouped into a "threa
Headers can be added inside a rule by calling the `mailActions.addHeader()` method before calling the respective `mailActions.sendMail()` method.
See the example below.
:::: tabs
::: tab DSL
```java
rule "Send Mail with a 'Reference' header; for threaded view in e-mail client"
when
@ -173,5 +205,17 @@ then
mailActions.sendMail("mail@example.com", "Test subject", "Test message text")
end
```
:::
::: tab JavaScript
```javascript
val mailActions = actions.get("mail","mail:smtp:sampleserver")
mailActions.addHeader("Reference", "<unique-thread-identifier>")
mailActions.sendMail("mail@example.com", "Test subject", "Test message text")
```
:::
::::
Note: in the case of the "Reference" header, the `<unique-thread-identifier>` has to be an ASCII string enclosed in angle brackets.