new: [opensem] add charm

This commit is contained in:
Valentin Lab
2025-09-25 16:31:23 +02:00
commit 32b0ed5645
11 changed files with 642 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
#!/bin/bash
. lib/common
set -e
host=$(relation-get host)
port=$(relation-get port)
connection_security=$(relation-get connection-security)
auth_method=$(relation-get auth-method)
declare -A ENV
ENV[DRIVER]=smtp
ENV[HOST]="$host"
ENV[PORT]="$port"
case "$connection_security" in
"none")
ENV[ENCRYPTION]=null
;;
"ssl/tls")
ENV[ENCRYPTION]="tls"
;;
"ssl")
ENV[ENCRYPTION]="ssl"
;;
*)
error "Unsupported connection security: $connection_security"
exit 1
;;
esac
case "$auth_method" in
"none")
ENV[USERNAME]=null
;;
"password")
login=$(relation-get login) || true
ENV[USERNAME]="$login"
password=$(relation-get password) || true
ENV[PASSWORD]="$password"
;;
*)
error "Unsupported auth method: $auth_method"
exit 1
;;
esac
mail_from=$(relation-get mail-from) || true
if [ -n "$mail_from" ]; then
ENV[FROM_ADDRESS]="$mail_from"
fi
from_name=$(relation-get from-name) || true
if [ -n "$from_name" ]; then
ENV[FROM_NAME]="$from_name"
fi
for key in "${!ENV[@]}"; do
value=${ENV[$key]}
opensem:config-set "MAIL_$key" "$value"
done