Stalwart only reads credentials like STALWART_TOKEN from the environment variable, or as a literal param at the commandline in stalwart-cli.
Because of the inheritance and other security implications of the env variables some credential management tools outright don’t have feature to pass credentials as env variables (most famous of those is systemd credentials).
To read credentials from the files user needs to use some wrapper that sets the env varibales before launching stalwart other tools, which isn’t great.
It would be nice if stalwart could read those values from the files.
Easiest way to implement that is to add _FILE suffixed variables like STALWART_TOKEN_FILE, so they can be static and hardcoded in the service.
That is similar to what “Lego” ACME service has.
It can be not clear what to do when file that is pointed to by STALWART_TOKEN_FILE doesn’t exist, it could be ignored or it could be an error, or it could be a choice like with “-” prefixed paths in systemd ExecStart, I don’t have a strong opinion here. For a similar case in another project I decided to fail on a missing file, but not fail if the fail exists and is empty, if it is empty it is ignored.
And it isn’t clear what to do about the cli flags, should they be duplicated too?
Alternative could be to allow a single STALWART_ENV_FILE with --env-file flag or similar that will contain .env encoded kv pairs, then if that file is missing it would be an error, but if it exists and is empty it is basically ignored.