tclsendmail

sending mail using sendmail with attachment in Tcl


Hi I am trying to send mail using sendmail in Tcl with attachment.

This is my code as follows,

set mail_ids "dinesh@mydomain.com"



set msg {From: dinesh}
set timestamp [ clock format [clock seconds] -format {%d-%m-%Y-at-%HH-%MM-%Ss} ]
append msg \n "To:$mail_ids"

append msg \n "Subject: $subject"
append msg \n "Hi,\nPlease find the report generated on $timestamp.\n"
append msg \n "\nAuto-generated email via script\n"
append msg  [ exec cat db.config | uuencode db.config ]
#append msg $report

puts "Sending mail now ..... "


exec /usr/lib/sendmail -oi -t << $msg


puts "Mail sent."

While running this, I am getting the following error

wrong # args: should be "exec handle cmd"
    while executing
"exec cat db.config | uuencode db.config "
    invoked from within
"append msg  [ exec cat db.config | uuencode db.config ]"
    (file "./my_script" line 478)

I am having the file 'db.config' in the current directory where the script is running.

What mistake i am making here ?

Thanks in advance.


Solution

  • I made a mistake in my code. I had one proc named 'exec' with 2 arguments and I found that the code

    exec /usr/lib/sendmail -oi -t << $msg
    

    is calling out the user-defined 'exec' proc, not the tcl's exec, which is why it is throwing error as wrong # args: should be "exec handle cmd".

    Mr.Donal is correct. I did the same mistake as yours. Thanks Donal. :)