Description:
Parameters:
Comments:
The code:
proc mailTo { { to "" } { subject "" } { body "" } { attach "" } } { if { [ string match $to $subject ] } { return -code error "mailTo: missing required arguments" } set attachment {} if { [ llength $attach ] } { foreach filename $attach { if { [ file exists $filename ] } { append attachment "-a $filename " } } } else { foreach filename [ split $body " ," ] { if { ! [ file exists $filename ] } { set attachment {} break; } else { append attachment "-a $filename " } } } foreach agent { mutt pine mailx } { if { [ string length [ auto_execok $agent ] ] } { switch $agent { mailx { if { [ string length $attachment ] } { return -code error "mailTo: no mail agent supporting attachments found" } set mailpipe [ open "| $agent -s $subject $to" w ] break; } default { set mailpipe [ open "| $agent -s $subject $attachment $to" w ] break; } } ;## end of switch } ;## end of if } ;## end of foreach if { ! [ info exists mailpipe ] } { return -code error "mailTo: no usable mail agent found on system" } if { [ catch { puts $mailpipe $body close $mailpipe } err ] } { return -code error "mailTo: $err" } return {} }
JOB See as well A tcllib based smtp mailer package for a pure tcl solution.