Tag Archives: misc

simple email procedure for tcl in linux or unix system

Quick Code:
Here is a sample procedure for tcl that you can use to send email. This basically call the mail function built in linux or unix like system.
Usage: gQuickMail “subject” “sendToEmailAdress” “bodyMessage” “ccToEmail” “bccToEmail”
Git: git clone https://github.com/rvguiman/tcl.git (added in g_misc_utility.tcl)
Or Check the code below

proc gQuickMail { subject sendTo bodyMsg ccTo bccTo } {
        set qmsgHan [open "tempMsg.qmsg" w]
        puts $qmsgHan $bodyMsg
        close $qmsgHan
        puts "sending mail...."
        if { $ccTo != "" && $bccTo != "" } {
                catch { exec mail -s $subject -c $ccTo -b $bccTo $sendTo < tempMsg.qmsg } msg
                } elseif { $ccTo != "" && $bccTo == "" } {
                catch { exec mail -s $subject -c $ccTo $sendTo < tempMsg.qmsg } msg
                } elseif { $ccTo == "" && $bccTo != "" } {
                catch { exec mail -s $subject -b $bccTo $sendTo < tempMsg.qmsg } msg
                } else {
                catch { exec mail -s $subject $sendTo < tempMsg.qmsg } msg
                }
        puts $msg
        catch { exec rm -rf tempMsg.qmsg } msg
        puts $msg
        puts "closing gQMail"
        }