Option to define email sender address

This commit is contained in:
Jeremy Gardais 2023-02-03 16:25:17 +01:00
parent 1ae8b95758
commit b0dc0934a4
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 27 additions and 2 deletions

View File

@ -54,7 +54,8 @@ readonly MIN_SIZE_INT_DEFAULT="10"
readonly MIN_SIZE_UNIT_DEFAULT="MB" readonly MIN_SIZE_UNIT_DEFAULT="MB"
readonly MIN_SIZE_DEFAULT="${MIN_SIZE_INT_DEFAULT}${MIN_SIZE_UNIT_DEFAULT}" readonly MIN_SIZE_DEFAULT="${MIN_SIZE_INT_DEFAULT}${MIN_SIZE_UNIT_DEFAULT}"
## Default domain for email addresses ## Default domain for email addresses
readonly USER_EMAIL_DOMAIN_DEFAULT=$(hostname -d) USER_EMAIL_DOMAIN_DEFAULT=$(hostname -d) ; readonly USER_EMAIL_DOMAIN_DEFAULT
SENDER_EMAIL_ADDRESS_DEFAULT="duplicati@$(hostname --fqdn --)" ; readonly SENDER_EMAIL_ADDRESS_DEFAULT
## Colors ## Colors
readonly PURPLE='\033[1;35m' readonly PURPLE='\033[1;35m'
@ -78,6 +79,12 @@ EXAMPLES:
- Apply to a specific directory (/mnt/remote.duplicati) - Apply to a specific directory (/mnt/remote.duplicati)
${PROGNAME} --dir /mnt/remote.duplicati ${PROGNAME} --dir /mnt/remote.duplicati
- Use a specific email address for sender
${PROGNAME} --sender "admin@domain.tld"
- Use a specific email address and name for sender
${PROGNAME} --sender "Duplicati no-reply <admin@domain.tld>"
OPTIONS: OPTIONS:
-d,--dir,--directory -d,--dir,--directory
Path where users home directory are stored Path where users home directory are stored
@ -91,6 +98,10 @@ OPTIONS:
Domain used to build user's email address. Domain used to build user's email address.
(default: ${USER_EMAIL_DOMAIN_DEFAULT}). (default: ${USER_EMAIL_DOMAIN_DEFAULT}).
--sender,--mail-sender,--sender-mail
Email address used to send mails to users.
(default: ${SENDER_EMAIL_ADDRESS_DEFAULT}).
--debug --debug
Enable debug messages. Enable debug messages.
@ -195,6 +206,12 @@ define_vars() { # {{{
readonly user_email_domain="${USER_EMAIL_DOMAIN_DEFAULT}" readonly user_email_domain="${USER_EMAIL_DOMAIN_DEFAULT}"
fi fi
## }}} ## }}}
## If sender_email_address wasn't defined (argument) {{{
if [ -z "${sender_email_address}" ]; then
## Use default value
readonly sender_email_address="${SENDER_EMAIL_ADDRESS_DEFAULT}"
fi
## }}}
} }
# }}} # }}}
@ -441,7 +458,9 @@ main() { # {{{
Taille précédente pour cette sauvegarde/Previous size for this backup : ~${backup_dir_previous_size} ${min_size_unit} (compress). Taille précédente pour cette sauvegarde/Previous size for this backup : ~${backup_dir_previous_size} ${min_size_unit} (compress).
Taille actuelle pour cette sauvegarde/Current size for this backup : ~${backup_dir_current_size} ${min_size_unit} (compress). Taille actuelle pour cette sauvegarde/Current size for this backup : ~${backup_dir_current_size} ${min_size_unit} (compress).
La différence de taille (~${backup_dir_compare_size} ${min_size_unit}) est inférieure au minimum attendu (${min_size}). La différence de taille (~${backup_dir_compare_size} ${min_size_unit}) est inférieure au minimum attendu (${min_size}).
--- ---
The difference (~${backup_dir_compare_size} ${min_size_unit}) is bellow the minimum expected size (${min_size}). The difference (~${backup_dir_compare_size} ${min_size_unit}) is bellow the minimum expected size (${min_size}).
" >> "${user_email_template}" " >> "${user_email_template}"
### }}} ### }}}
@ -479,7 +498,7 @@ Recorded informations from previous tests :
### }}} ### }}}
### Send email {{{ ### Send email {{{
debug_message "| Send email content (${user_email_template}) to user email address (${RED}${user_email_address}${COLOR_DEBUG})." debug_message "| Send email content (${user_email_template}) to user email address (${RED}${user_email_address}${COLOR_DEBUG})."
mail -r "duplicati@duplicati.$(hostname --domain)" -s "Duplicati backup warning" "${user_email_address}" < "${user_email_template}" \ mail -a "From:${sender_email_address}" -s "Duplicati backup warning - ${user_dir}" "${user_email_address}" < "${user_email_template}" \
|| error_message "Can't send content (${user_email_template}) by mail to user (${user_email_address}). See --debug option for more options." 23 || error_message "Can't send content (${user_email_template}) by mail to user (${user_email_address}). See --debug option for more options." 23
### }}} ### }}}
fi fi
@ -558,6 +577,12 @@ if [ ! "${NBARGS}" -eq "0" ]; then
## Define var ## Define var
readonly user_email_domain="${1}" readonly user_email_domain="${1}"
;; ;;
--sender|--mail-sender|--sender-mail )## Define sender_email_address
## Move to the next argument
shift
## Define var
readonly sender_email_address="${1}"
;;
--debug ) ## debug --debug ) ## debug
DEBUG=0 DEBUG=0
debug_message "--- Manage argument BEGIN" debug_message "--- Manage argument BEGIN"