#!/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