Here’s the Tcl code we use for sending email.
It should work on Unix/Linux/Windows Tcl versions that have the mime and smtp packages available. We’re running this code on Cloveleaf 5.6, Tcl version 8.4.12.
Add your specific values for defaultSmtpForwarder and defaultSmtpSender.
As I recall, the email server in defaultSmtpForwarder must be set up to allow forwarding for the user sending the email.
namespace eval crmcEmail {
variable defaultSmtpForwarder
variable defaultSmtpSender
}
proc crmcEmail::sendMessage { subject body recipientList args } {
global env
variable defaultSmtpForwarder
variable defaultSmtpSender
package require smtp
package require mime
# defaults
set smtpSnd $defaultSmtpSender
set smtpServ $defaultSmtpForwarder
set msgStyle EMAIL
switch -exact [llength $args] {
0 {
# no args supplied – normal operation
}
1 {
# Just the msg style flag supplied
set msgStyle [string trim [string toupper [lindex $args 0]]]
}
2 {
# msg style and smpt sender
set msgStyle [string toupper [lindex $args 0]]
set smtpSnd [lindex $args 1]
}
default {
# msg style, smpt sender AND smtp forwarder
set msgStyle [string toupper [lindex $args 0]]
set smtpSnd [lindex $args 1]
set smtpServ [lindex $args 2]
}
}
# protect against empty sender
if { $smtpSnd eq “” } {
set smtpSnd $defaultSmtpSender
}
# protect against empty server
if { $smtpServ eq “” } {
set smtpServ $defaultSmtpForwarder
}
#puts “msgStyle= $msgStyle, smtpSnd= $smtpSnd, smptServ= $smtpServ”
if { [catch {set callingProc [lindex [info level -1] 0]} errs] } {
set callingProc “UNKNOWN”
}
if { [catch {set workingEnv [string toupper $env(HCISITE)]} errs] } {
set workingEnv “hciSiteUNDEFINED”
}
if { $msgStyle eq “TXT” } {
# terse txt style
set token [mime::initialize -canonical text/plain -string “[info hostname] [clock format [clock seconds] -format “%m/%d %H:%M”] $body”]
mime::setheader $token Subject “$subject”
} else {
# Standard verbose email style
set token [mime::initialize -canonical text/plain -string ” Server: $workingEnv [info hostname]n[clock format [clock seconds] -format “Server Time: %m/%d/%Y %H:%M:%S”]n proc: $callingProcnn$body”]
mime::setheader $token Subject “$workingEnv [info hostname] $subject”
}
mime::setheader $token From “$smtpSnd”
mime::setheader $token To [join $recipientList ,]
smtp::sendmessage $token -recipients [join $recipientList ,] -servers $smtpServ -atleastone 1
mime::finalize $token
}
Jeff Dinsmore
Chesapeake Regional Healthcare