Email from a tcl proc on Windows server

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Email from a tcl proc on Windows server

  • Creator
  • #50948
    Alka Sharma

    Hi Everyone,

    Anyone out there using blat on windows server for emails. I need help in writing the correct syntax to execute blat from within tcl.

    This is what I am trying to achieve:

    If ordering and billing provider is missing in ZS1 segment, send an email out to a distribution list.

    Here is my proc

    Name: uchc_ngen_email

    # Purpose:

    # UPoC type: tps

    # Args: tps keyedlist containing the following keys:

    #       MODE    run mode (“start”, “run” or “time”)

    #       MSGID   message handle

    #       ARGS    user-supplied arguments:



    # Returns: tps disposition list:



    proc uchc_ngen_email { args } {

       keylget args MODE mode               ;# Fetch mode

       set dispList {} ;# Nothing to return

       switch -exact — $mode {

           start {

               # Perform special init functions

       # N.B.: there may or may not be a MSGID key in args


           run {

       # ‘run’ mode always has a MSGID; fetch and process it

               keylget args MSGID mh

    # Here we retrieve the original message

    set msg [msgget $mh]


    #Body of the email

    set EmailMsg “$msg”

    #Email subject

    set subject “Missing ordering and billing provider”

    #Email Address

    set address “

    #Parse the Message

    lassign [split [crange $msg 3 7] {}] fsep csep rsep esep ssep

    set msglist [split $msg r]

    #Find the segment

    set seg [lmatch -regexp [split $msg r] ^ZS1]

    set billingprov [lindex [split $seg $fsep] 4]

    echo “Billing Provider” $billingprov

    set orderingprov [lindex [split $seg $fsep] 5]

    echo “Ordering provider” $orderingprov


    if {[cequal $billingprov “”] && [cequal $orderingprov “”]} {

             set cmd “blat -subject $subject -body $EmailMsg -to $address”

    if {[catch $cmd result]} {

    echo “ERROR: An error occurred running “$cmd”.”

    echo ”     Result was: $result”


    lappend dispList “KILL $mh”

    return $dispList

    } else {

    lappend dispList “CONTINUE $mh”

    return $dispList



           time {

               # Timer-based processing

       # N.B.: there may or may not be a MSGID key in args



           shutdown {

       # Doing some clean-up work



       return $dispList


Viewing 3 reply threads
  • Author
    • #68159
      Chris Williams

      You may be having a syntax issue. From

      Blat -to [optional switches]

       : file with the message body to be sent. If your message body is on the command line, use a hyphen (-) as your first argument, and -body followed by your message. If your message will come from the console/keyboard, use the hyphen as your first argument, but do not use body option.

      Much more documentation available on their website.

    • #68160
      Ron Archambault

      It’s been a while since I’ve done this on windows, but I do remember having to exec it to cmd to get it to run. Try this.

      set cmd “exec cmd /C blat -subject $subject -body $EmailMsg -to $address”

    • #68161
      Alka Sharma

      Thanks so much! I will try your option.

    • #68162
      Alka Sharma

      I am able to send an email using tcl proc now. Thanks Ron for all your help.

      I had to to the following:

      I had to define my credentials on the SMTP server. I then sent the email using the command line from the cloverleaf server and it worked. Then I used the same command from my tcl proc. I had to escape spaces, “|” to send the email. I am writing this and attaching my tcl proc so someone else can benefit from this.


Viewing 3 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
Topic Tags