Clovertech
› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Alert using email
I was wondering if anyone had a sample script that they use for email notifications. We are on a Windows 2003 server running Cloverleaf 5.5.
There are many Windows based command line mailer available, bmail comes to mind. SImply Google for them. Then you cal exec from a Tcl script.
We also use a package that I modified called tclMail.
We also have a TCL proc which uses the mime and smtp TCL packages (which you would have to download and install); this assumes you have SMTP access to your mail server.
###################################################################### # send_simple_email – sends email using smtp/mime packages # Args: recipients comma-separated email addresses # subject message subject # body message body # Returns: nothing # proc send_simple_email {recipients subject body} {
package require mime package require smtp
set token [mime::initialize -canonical text/plain -string $body] mime::setheader $token Subject $subject smtp::sendmessage $token -header [list From “FromName “] -header “To $recipients” -servers “mail.domain.com” mime::finalize $token
return 0 }
where can i find those
Check in your $HCIROOT/tcl/lib/tcllib1.8 directory. If you don’t have them sourceforge.net is good “source” for open source code.
ok i have the packages but how do i use this script
I have used shell scripts with alerts, but I think using Tcl is same process. You can call your Tcl file and any arguments in the action section.
oh i am calling the proc using the following line.
Try removing the braces around your arguments:
sendEmailMessage cloverleaf@here.com rlp71@some.com xx.xx.x.xx subject body
You may have to put quotes or braces around any argument that contain white space like your subject or body.
In your .tcl file call $argv.
ie. proc sendmail {address text} {
puts “address is $address”
puts “text is $text”
}
set address [lindex $argv 0]
set text [lindex $argv 1]
sendmail $address $text
Then from the shell tclsh arg arg
is sendmail a tcl command that comes with cloverleaf?
any ideas why it will not work
called it from the alert as tcl
call:
sendmail XXXXX@XXXXX.com “Thread Down”
proc:
proc sendmail {address text} {
{
return
That was just an example proc I used with using argv. So, you run your tcl file like this from the cmd line.
H:>tclsh C:TEMPsendmail.tcl gary “Hi there” address is gary text is Hi there
Under action section when building an alert, use the alert action of “exec”.
Two more things I forgot 💡 make sure you have the path to tclsh in the top line of your script using #!. Also, make the file is executable.
Hope this helps 😉
package require tclMail puts “Hello, World!”
Error: can’t find package tclMail while executing “package require tclMail” (file “tclmail.tcl” line 1)
Where can I get the tclMail package?
-- Max Drown (Infor)