Add suject template, pretty_from field and more mail server configuration
All checks were successful
/ test (push) Successful in 13s

This commit is contained in:
phil 2024-12-13 15:57:40 +01:00
parent d159254fdf
commit ab824960ac
4 changed files with 237 additions and 38 deletions

View file

@ -46,22 +46,33 @@ Configuration is done by environment variables, prefixed by `SMS_HANDLER_`:
* `SMS_HANDLER_MAIL_TO`: destination email address (default: *username*@localhost)
* `SMS_HANDLER_MAIL_SERVER`: address of the mail server (default: localhost)
* `SMS_HANDLER_MAIL_SERVER_PORT`: port of the mail server (default: 25)
* `SMS_HANDLER_MAIL_SERVER_START_TLS`: initiate mail server connection with TLS (default: no)
* `SMS_HANDLER_MAIL_SERVER_USERNAME`: username of the mail server (default: None)
* `SMS_HANDLER_MAIL_SERVER_PASSWORD`: port of the mail server (default: None)
* `SMS_HANDLER_MAIL_SERVER_START_TLS`: initiate mail server connection with TLS, eg. when using port 587 (default: no)
* `SMS_HANDLER_MAIL_SERVER_USE_TLS`: use mail server connection TLS, eg when using prot 465 (default: no)
* `SMS_HANDLER_MAIL_SUBJECT`: used to format the subject of the mails
* `SMS_HANDLER_MAIL_TEMPLATE`: used to format the body of the mails
* `SMS_HANDLER_MAIL_ENABLE`: no or false to disable mails (default: yes)
The default settings work with a mail server runs on the localhost,
and mails are sent to the user that owns the process.
The `SMS_HANDLER_MAIL_TEMPLATE` variable is used with Python `str.format()`.
### Templates
The `SMS_HANDLER_MAIL_TEMPLATE` and `SMS_HANDLER_MAIL_SUBJECT` variable use the standard
Python [string formatting](https://peps.python.org/pep-3101/).
See for example [here](https://www.w3schools.com/python/python_string_formatting.asp) for simple examples.
The field names are the same as the default JSON setting in the *SMS to URL Forwarder* app.
Additionally, a `pretty_from` variable can be used in the templates, which combines the phone number
of the sender with its name if found in the SMS record in the `fromName` field.
The default setting formats emails as below:
```text
{text}
---
From: {from} {fromName}
From: {pretty_from}
Sent: {sentStamp:%c}
Received: {receivedStamp:%c}
Sim: {sim}