TCL function for email

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL function for email

  • Creator
    Topic
  • #53105
    Faraz Khan
    Participant

      proc fnSendMail { emailFrom emailSubject emailBody emailRecipients args } {

      package require mime

      package require smtp

       

      if [ catch {

       

                     set token [mime::initialize -canonical text/plain -string $emailBody]

                     mime::setheader $token Subject $emailSubject

                     smtp::sendmessage $token -header

        -header “To $emailRecipients” -servers “YourSMTP.YourDomain.ca”

                       mime::finalize $token

                       return 0

        } err ] {

        #puts “fnSendMail Error: $err”

        return $err

        }

        }

        usage: fnSendMail $emailFrom $emailSubject $emailBody $emailRecipients

        Note: In the function you need to replace the value of “YourSMTP.YourDomain.ca” with your SMTP server info.

    Viewing 13 reply threads
    • Author
      Replies
      • #76578
        Troy Morton
        Participant

          Hi Faraz,

          Did you know that Cloverleaf comes with a Mail object built-in called, TclMail?

        • #76579
          Faraz Khan
          Participant

            Hi Troy,

            Thanks a lot for the info!

            Greatly appreciated.

            Regards,

            Faraz

          • #76580
            Troy Morton
            Participant

              –added the attachment again–

              I thought that the tclMail object came with Cloverleaf but apparently its something that we got from Charlie Bursell at a training class after our implementaiton.

              I’ve attached the tclMail package.

            • #76581
              David Harrison
              Participant

                Troy,

                I’ve downloaded tclMail.tcl a couple of times and it’s incomplete – it terminates at line 155. I’d be grateful if you could upload it again.

                Thanks,

                Dave

              • #76582
                Troy Morton
                Participant

                  Okay, I re-attached the file and re-downloaded it to make sure it was complete this time.  Let me know if you continue to have issues.

                • #76583
                  David Harrison
                  Participant

                    That’s better, I’ve got it all now.

                    Many thanks,

                    Dave

                  • #76584
                    Faraz Khan
                    Participant

                      Hi Troy,

                      Thanks a lot for sharing the code with us!

                      It’s really cool Man!

                      Regards,

                      Faraz

                    • #76585
                      Troy Morton
                      Participant

                        My pleasure!

                      • #76586
                        Ryan Wilson
                        Participant

                          I keep getting an error message that says it can’t find package tclMail.  I added the tclMail.tcl file to my tclprocs directory and ran the mktclindex command from there, but it still can’t find it.  Any ideas?

                        • #76587
                          Troy Morton
                          Participant

                            The file goes in $HCIROOT/tclprocs/lib.

                          • #76588
                            Ryan Wilson
                            Participant

                              It still doesn’t work.  I am running Cloverleaf in a Windows server 2003 environment.  There is not a ‘lib’ folder under tclprocs in root directory or in site directory.  I created it anyways and ran mktclindex and it still can’t find it.  I tried running pkg_mkIndex command, but it’s not recognized by Windows.

                            • #76589
                              Troy Morton
                              Participant

                                Hmmm … there is probably something special about the Windows environment.  There must be somewhere that your Tcl libraries are located on the server.  To my knowledge the directory structure of Clovelreaf does not change by platform, but maybe I’m wrong.

                                What version of Cloverleaf are you using?  We are on 5.7 rev2.  I guess it’s possible that newer versions may place the Tcl libraries in different locations.

                                I would suggest calling or emailing Cloverleaf support to see where you should place Tcl Library files that you wish to add to your implementation.  In theory, you should be able to author your own Tcl Library files.  So, they should have no problem telling you where they should be placed.

                              • #76590
                                Ryan Wilson
                                Participant

                                  We are on 5.8.

                                • #76591
                                  Charlie Bursell
                                  Participant

                                    run mkpkgindex in the tclprocs/lib directory

                                    Then in your proc, probably in start mode

                                        package require tclMail

                                             

                                    you will need code similar to the below.  Remember mail is an array  

                                     

                                     

                                    #####################################################

                                       # mailTo – Send e-mail

                                       #           Call tclMail by setting up array as follows

                                       #             Key   R/O/C           Contents

                                       #          



                                     


                                       #           TO         R            Mail to Address

                                       #           MSG        R            Mail message

                                       #           SUBJ       R            Mail Subject

                                       #           AUTH       O            Type Authorization Require

                                       #           NAME       C            Login Name

                                       #           PASS       C            Password

                                       #           PORT       O            Mail Port to use (Default 25)

                                       #           SERVER     R            SMTP Server address

                                       #           DOMAIN     R            Mail domain

                                       #           USER       R            Mail address of Authorized user

                                       #           FROM       O            Mail From address (def CLOVERLEAF)

                                       #

                                       #           Change array parameters as required.

                                       # It is assumed this routine is called with all needed array elements

                                       # set except for the mail message and TO: address(s)

                                       #

                                       # The message is passed as a string

                                       ########################################################################

                                       proc mailTo {msg} {

                                           variable procName       ;# Procedure name

                                           variable mail           ;# The mail array

                                           variable toADDRESS      ;# Send to addresese

                                           set mail(MSG) $msg

                                           # If not connecting to MS Exchange server, remove EHLO as arg

                                           if {[catch {set err [tclMail::SendMail mail EHLO]} bad]} {

                                               set err $bad

                                           }

                                           if {$err ne “”} {

                                               echo n$procName: Error sending mail to: $mail(TO)

                                                       echo nMessage is: $msgnnError is: $errn

                                           }

                                           return “”

                                       }

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