Skip to content

Module thc_MailAlert

Andreas Drollinger edited this page Nov 8, 2019 · 14 revisions

Mail alert

This module provides functions to send mail alerts.


Proc: thc::MailAlert::Configure

Configures the mail delivery method. Mails can be delivered either via a custom mail procedure (method=custom), or using the Tcl smtp package. For this second case the mail delivery can either be managed by the main THC Tcl process (method=direct_sync) or by a specific Tcl process (method=direct_async). This latest method avoids eventual interruptions of the main THC Tcl process in case the SMTP server response is delayed.

Parameters

Parameters Description
-method <DeliveryMethod> Mail delivery method. Has to be 'custom', 'direct_sync' or 'direct_async' (default)
[-custom_command <CustomCommand>] Specifies the custom mail command that will be called if the custom delivery method is selected. The argument list of the custom command and the use of the Unix mail command 'mail' is shown in the example below.
[-direct_args <Direct delivery arguments>] Arguments transferred to smtp::sendmessage if one of the direct mail delivery methods is selected
-debug 0|1 If set to 1 some additional log information are displayed that help debugging the email delivery method. Default: 0

Returns

-

Examples

 # 1)
 package require tls
 thc::MailAlert::Configure \
    -method direct_async \
    -direct_args {-servers mail.my_host.com -ports 25
                  -username my_name@my_host.xyz -password my_pw_123
                  -usetls 1}

 # 2)
 thc::MailAlert::Configure \
    -method custom \
    -custom_command mail_custom_send

 proc mail_custom_send {Title Message RecipientList From} {
    # Backslash double quotes
    regsub -all "\"" $Message "\\\"" Message
    regsub -all "\"" $Title "\\\"" Title

    # Call the Unix mail command to send the message
    exec bash -c "echo \"$Message\" | mail -s \"$Title\" -r $From $RecipientList"
 }

See also

thc::MailAlert::Send


Proc: thc::MailAlert::Send

Sends a mail message. Send sends a mail message to one or to multiple destination addresses. To use this command the command mail needs to be available and configured.

Parameters

Parameters Description
-to <ToAddress> Destination address. Multiple addresses can be specified by repeating this argument
[-from <From>] Sender address. Default: localhost
[-title <Title>] Message title
Message Mail message

Returns

-

Examples

 thc::MailAlert::Send -to knopf@vaucher.ch -to 0041791234567@sms.ecall.ch \
                     -from myhome.vaucher@bluewin.ch -title "Alarm alert" \
                     "Sensor $Sensor triggered"

See also

thc::MailAlert::Configure