Modifications to get sendmail.tcl working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2011 12:32 PM
As requested by Joseph Clarke, I am opening a new thread.
My original question is what needs to be done so that the sendmail.tcl script is able to send its notifications via my mail server which has the following greeting message:
220-gateway.firewall.cx ESMTP Exim 4.69 #1 Tue, 13 Dec 2011 20:44:49 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
Joseph recommended the following:
Can you change the SMTP server to use a space instead of a '-' after the response code? As you noted, your current banner is not supported by EEM. The workaround would be to take the library code at tmpsys:/lib/tcl/smtp_lib.tcl, modify it to work with your SMTP server, modify the namespace from ::cisco::lib to something like ::customer::lib, change your code to use ::customer::lib::smtp_*, and then copy the modified smtp_lib.tcl back to your device as a user library file.
My questions are as follow:
1) I have located on line 142 of smtp_lib.tcl the following code which has been modified:
if [catch {smtp_chk_reply $sock 220-} result] {
return -code error $result
To
if [catch {smtp_chk_reply $sock 220-gateway.firewall.cx} result] {
return -code error $result
Will I need to inset all three lines of my SMTP Server's response or will this piece be enough (until the first 'space')?
2) "modify the namespace from ::cisco::lib to something like ::customer::lib"
Do I make this change at the beggining of smtp_lib.tcl (see below) or anywhere I see ::cisco::lib in the smtp_lib.tcl file ?
namespace eval ::cisco::lib {
namespace export smtp_subst smtp_send_email
To
namespace eval ::custom::lib {
namespace export smtp_subst smtp_send_email
3) In sendmail.tcl, Here is what I have changed, but how can I define the path for custom::lib? :
# Namespace imports
#
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
To
# Namespace imports
#
namespace import ::cisco::eem::*
namespace import ::custom::lib::*
4) I've uploaded smtp_lib.tcl tp flash:/tcl and registered it as a user library with the following command. Is this correct? Am I missing anything else?:
event manager directory user library flash:/tcl
Because I am not a programmer, I'd highly appreciate any additional instructions or corrections in case I have misunderstood anything.
Thank you
Chris.
- Labels:
-
Network Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2011 03:54 PM
Right after the standard namespace imports, add:
source "custom_smtp_lib.tcl"
You'll need to rename your lib, and re-run the event manager directory command. Then, after the source, add:
namespace import ::custom::lib::*
Then modify your code that calls smtp_* functions to call ::custom::lib::smtp_* functions and you should be set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2011 02:53 PM
Joseph,
Thank you so much for your reply.
I've tried to work out the modifications based on the information provided and what I could understand but it seems like I'm missing something.
If you can spare 5 minutes of your time and take a quick look, I'd really appreciated it.
I've attached the modified files for you to look at and these are the commands I run to execute them:
no event manager policy sendmail.tcl
event manager directory user policy flash:
event manager directory user library flash:/tcl
event manager environment _email_server xxx.xxx.xxx.xxx
event manager environment _email_from cisco@somedomain.com
event manager environment _email_to myemailaddress
event manager policy sendmail.tcl
Any help is much appreciated.
Thank you.
p.s I've modified the sendmail script so that it emails me once it see a specific system console message (ph. number)
Chris.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2011 05:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 12:45 PM
Joseph,
Thank you very much for your time - I'll give them a try and inform you as soon as I can.
Cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 01:23 PM
Joseph,
I just tried the scripts and still receive the following error:
036740: Dec 19 23:16:03.692: %HA_EM-6-LOG: sendmail.tcl: Creating mail header...
036741: Dec 19 23:16:04.360: %HA_EM-6-LOG: sendmail.tcl: smtp_send_email: error connecting to mail server:
can't read "reply_code_str(220-gateway.xxxxxx.xx)": no such element in array
Here is the EM commands I used to load the scripts:
no event manager policy sendmail.tcl
event manager directory user policy flash:
event manager directory user library flash:/tcl
event manager environment _email_server 74.200.84.4
event manager environment _email_from cisco@xxxxx.xxx
event manager environment _email_to chris@xxxxxxx.xxx
event manager policy sendmail.tcl
In custom_smtp_lib.tcl, line 142 (
if [catch {smtp_chk_reply $sock )
, I have entered the output of my SMTP server, but it seems I am missing something.
Any suggestions ?
Many thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 03:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 03:09 PM
Joseph,
I tried the new file, but still are receiving the same error.
I ensured I removed and re-added the user library files using the following commands:
no event manager policy sendmail.tcl
no event manager directory user policy flash:
no event manager directory user library flash:/tcl
event manager directory user policy flash:
event manager directory user library flash:/tcl
event manager environment _email_server xxx.xxx.xxx.xxx
event manager environment _email_from cisco@xxx.xxx
event manager environment _email_to chris@xxx.xxx
event manager policy sendmail.tcl
Do you have any additional ideal on how we can overcome this issue ?
Friendly regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 03:13 PM
Are you sure that:
1. The value in the library, "220-gateway.datavision.gr" matches what your SMTP server is returning
2. You have loaded the right version of sendmail.tcl which uses ::custom::lib::smtp_send_email to send email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 03:24 PM
Joseph,
I've double-checked all the above, however let me paste once again the full output of my mail server:
220-gateway.datavision.gr ESMTP Exim 4.69 #1 Tue, 20 Dec 2011 01:22:30 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
My understanding is that I need to insert in the 'custom_smtp_lib.tcl file, only the first line, up to the first space character.
Correct?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 03:33 PM
Correct. Then in your sendmail.tcl file, you should see the call to ::custom::lib::smtp_send_email instead of just smtp_send_email. Here is a debug version of the custom_smtp_lib.tcl file. This should print an XXX message on the terminal with the status code that was read from the server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2011 02:10 PM
Joseph,
I've loaded the new file and executed the necessary event manager commands as previously, but the output remains the same.
I cannot understand why this is not working! Is there any show or debug commands I can use to get more information and help troubleshoot this issue ?
Thanks again,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2011 02:28 PM
If you're not seeing a line that starts with XXX chances are you have not loaded the correct version of sendmail.tcl. What is the output of "more tmpsys:/eem_policy/sendmail.tcl" on your router?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2011 01:05 PM
Joseph,
There is something wired happening here. I rebooted the router and discovered that the flash:/tcl directory was not available anymore. I re-created the directory, uploaded the two tcl files in there and tried it again with the following result:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: while executing
-6-LOG: sendmail.tcl: "namespace import ::custom::lib::*"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "$slave eval $Contents"
-6-LOG: sendmail.tcl: (procedure "eval_script" line 7)
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "eval_script slave $scriptname"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "if {$security_level == 1} { #untrusted script
-6-LOG: sendmail.tcl: interp create -safe slave
-6-LOG: sendmail.tcl: interp share {} stdin slave
-6-LOG: sendmail.tcl: interp share {} stdout slave
-6-LOG: sendmail.tcl: ..."
-6-LOG: sendmail.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
-6-LOG: sendmail.tcl: Tcl policy execute failed:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: while executing
-6-LOG: sendmail.tcl: "namespace import ::custom::lib::*"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "$slave eval $Contents"
-6-LOG: sendmail.tcl: (procedure "eval_script" line 7)
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "eval_script slave $scriptname"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "if {$security_level == 1} { #untrusted script
-6-LOG: sendmail.tcl: interp create -safe slave
-6-LOG: sendmail.tcl: interp share {} stdin slave
-6-LOG: sendmail.tcl: interp share {} stdout slave
-6-LOG: sendmail.tcl: ..."
-6-LOG: sendmail.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
-6-LOG: sendmail.tcl: Tcl policy execute failed:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: while executing
-6-LOG: sendmail.tcl: "namespace import ::custom::lib::*"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "$slave eval $Contents"
-6-LOG: sendmail.tcl: (procedure "eval_script" line 7)
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "eval_script slave $scriptname"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "if {$security_level == 1} { #untrusted script
-6-LOG: sendmail.tcl: interp create -safe slave
-6-LOG: sendmail.tcl: interp share {} stdin slave
-6-LOG: sendmail.tcl: interp share {} stdout slave
-6-LOG: sendmail.tcl: ..."
-6-LOG: sendmail.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
-6-LOG: sendmail.tcl: Tcl policy execute failed:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: while executing
-6-LOG: sendmail.tcl: "namespace import ::custom::lib::*"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "$slave eval $Contents"
-6-LOG: sendmail.tcl: (procedure "eval_script" line 7)
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "eval_script slave $scriptname"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "if {$security_level == 1} { #untrusted script
-6-LOG: sendmail.tcl: interp create -safe slave
-6-LOG: sendmail.tcl: interp share {} stdin slave
-6-LOG: sendmail.tcl: interp share {} stdout slave
-6-LOG: sendmail.tcl: ..."
-6-LOG: sendmail.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
-6-LOG: sendmail.tcl: Tcl policy execute failed:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: while executing
-6-LOG: sendmail.tcl: "namespace import ::custom::lib::*"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "$slave eval $Contents"
-6-LOG: sendmail.tcl: (procedure "eval_script" line 7)
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "eval_script slave $scriptname"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "if {$security_level == 1} { #untrusted script
-6-LOG: sendmail.tcl: interp create -safe slave
-6-LOG: sendmail.tcl: interp share {} stdin slave
-6-LOG: sendmail.tcl: interp share {} stdout slave
-6-LOG: sendmail.tcl: ..."
-6-LOG: sendmail.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
-6-LOG: sendmail.tcl: Tcl policy execute failed:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
-6-LOG: sendmail.tcl: while executing
-6-LOG: sendmail.tcl: "namespace import ::custom::lib::*"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "$slave eval $Contents"
-6-LOG: sendmail.tcl: (procedure "eval_script" line 7)
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "eval_script slave $scriptname"
-6-LOG: sendmail.tcl: invoked from within
-6-LOG: sendmail.tcl: "if {$security_level == 1} { #untrusted script
-6-LOG: sendmail.tcl: interp create -safe slave
-6-LOG: sendmail.tcl: interp share {} stdin slave
-6-LOG: sendmail.tcl: interp share {} stdout slave
-6-LOG: sendmail.tcl: ..."
-6-LOG: sendmail.tcl: (file "tmpsys:/lib/tcl/base.tcl" line 50)
-6-LOG: sendmail.tcl: Tcl policy execute failed:
-6-LOG: sendmail.tcl: can't import command "smtp_send_email": already exists
Any ideas where to go from here on ?
Thank you once again!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2011 03:50 PM
