cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1275
Views
5
Helpful
19
Replies
Highlighted

sendmail tcl eem policy not working

Hello,

I'm having trouble to get the library smtp_send_email working.

I have a tcl script which I register with eem. I set all the env vars like _email_server, _email_to etc.

But when the script is executed i get the following message:

002716: Nov 25 2015 12:54:22.764 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_connect : attempt 1
002717: Nov 25 2015 12:54:23.023 CET: [fh_smtp_debug_cmd]
002718: Nov 25 2015 12:54:23.023 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_read  : 220 <mailservername> -- Server ESMTP (PMDF V6.6#32005)
002719: Nov 25 2015 12:54:23.023 CET: [fh_smtp_debug_cmd]
002720: Nov 25 2015 12:54:23.023 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_write : HELO es334A2.mydomain.de
002721: Nov 25 2015 12:54:23.089 CET: [fh_smtp_debug_cmd]
002722: Nov 25 2015 12:54:23.089 CET:
es334A2#%HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_read  : 250 <mailservername> OK, [172.19.17.196].
002723: Nov 25 2015 12:54:23.089 CET: [fh_smtp_debug_cmd]
002724: Nov 25 2015 12:54:23.089 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_write : MAIL FROM:<es334A2@mydomain.com>
002725: Nov 25 2015 12:54:23.170 CET: [fh_smtp_debug_cmd]
002726: Nov 25 2015 12:54:23.170 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_read  : 250 2.5.0 Address Ok.
002727: Nov 25 2015 12:54:23.170 CET: [fh_smtp_debug_cmd]
002728: Nov 25 2015 12:54:23.170 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_write : RCPT TO:<me@mydomain.com>
002729: Nov 25 2015 12:54:23.250 CET: [fh_smtp_debug_cmd]
002730: Nov 25 2015 12:54:23.250 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_read  : 250 2.1.5 me@mydomain.com OK.
002731: Nov 25 2015 12:54:23.250 CET: [fh_smtp_debug_cmd]
002732: Nov 25 2015 12:54:23.250 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_write : DATA
002733: Nov 25 2015 12:54:23.317 CET: [fh_smtp_debug_cmd]
002734: Nov 25 2015 12:54:23.317 CET: %HA_EM-6-LOG: vlanmap.tcl : DEBUG(smtp_lib) : smtp_read  : 354 Enter mail, end with a single ".".
002735: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: list element in quotes followed by "." instead of space
002736: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:     while executing
002737: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: "smtp_send_email $mail_msg"
002738: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:     invoked from within
002739: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: "$slave eval $Contents"
002740: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:     (procedure "eval_script" line 7)
002741: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:     invoked from within
002742: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: "eval_script slave $scriptname"
002743: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:     invoked from within
002744: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: "if {$security_level == 1} {       #untrusted script
002745: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:      interp create -safe slave
002746: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:      interp share {} stdin slave
002747: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:      interp share {} stdout slave
002748: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: ..."
002749: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl:     (file "tmpsys:/lib/tcl/base.tcl" line 50)
002750: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: Tcl policy execute failed:
002751: Nov 25 2015 12:54:23.320 CET: %HA_EM-6-LOG: vlanmap.tcl: list element in quotes followed by "." instead of space
myswitch#

The Hardware is 2960X with IOS 15.2(4)E.

The event manager version is:

Embedded Event Manager Version 4.00
Component Versions:
eem: (rel9)1.2.6
eem-gold: (rel1)1.0.2
eem-call-home: (rel2)1.0.4
Event Detectors:
Name                Version   Node        Type
application         01.00     node0/0     RP
identity            01.00     node0/0     RP
mat                 01.00     node0/0     RP
neighbor-discovery  01.00     node0/0     RP
generic             01.00     node0/0     RP
routing             03.00     node0/0     RP
syslog              01.00     node0/0     RP
cli                 01.00     node0/0     RP
config              01.00     node0/0     RP
counter             01.00     node0/0     RP
crash               01.00     node0/0     RP
ds                  01.00     node0/0     RP
env                 01.00     node0/0     RP
gold                01.00     node0/0     RP
interface           01.00     node0/0     RP
ioswdsysmon         01.00     node0/0     RP
nf                  01.00     node0/0     RP
none                01.00     node0/0     RP
oir                 01.00     node0/0     RP
snmp                01.00     node0/0     RP
snmp-object         01.00     node0/0     RP
snmp-notification   01.00     node0/0     RP
test                01.00     node0/0     RP
timer               01.00     node0/0     RP

I don't understand the message: "list element in quotes followed by "." instead of space"

This is the code I use:

#smtp_send_email
if {$withmail == 1 } {
set mail_pre "Mailservername: <mailservername>\n"
append mail_pre "From: es334A2@mydomain.com\n"
append mail_pre "To: me@mydomain.com\n"
append mail_pre "Cc: \n"
append mail_pre "Subject: LINK UP\n"
append mail_pre " \n"
append mail_pre "Test1\n"
append mail_pre "Test2\n\n"

set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
puts stdout "mail_msg:\n$mail_msg"
puts stdout "routername: $routername"
if [catch {smtp_send_email $mail_msg} result] {
    error $result $errorInfo
}

Any help is very appreciated.

Kind regards,

Andreas

19 REPLIES 19
Highlighted
Hall of Fame Cisco Employee

Sorry, this slipped through the cracks, and I haven't had time to look at it.  I just cracked back open the code, and the problem is the string your mail server returns when you enter "DATA".  Most servers will reply with the the "." inside the string as opposed to the end followed by another period.  This breaks our email code.  If you add this code to your script after you import the cisco namespaces, it should work:

proc ::cisco::lib::smtp_chk_reply { sock succ_code } {
  variable reply_code_str

  set r [ smtp_read $sock ]
  if {$r == -1} {
      return -code error "Socket closed by remote server"
  }

  set k [lindex [split $r "\r\n"] 0]
  if {$k != $succ_code} {
      return -code error [concat From SMTP server: $r\n$reply_code_str($k)]
  }
}

Highlighted

Hi,

thanks for the reply. It Looks like we're almost there.

Now the error is different:

000120: Jan 19 2016 11:48:24.307 CET: %HA_EM-6-LOG: mail_test.tcl: error connecting to mail server:
000121: Jan 19 2016 11:48:24.307 CET: %HA_EM-6-LOG: mail_test.tcl: can't read "reply_code_str(220 "<hostname>" -- Server ESMTP (PMDF V6.6#32005))": no such element in Array

?

Highlighted
Hall of Fame Cisco Employee

Wrong split chars.  Try this:

proc ::cisco::lib::smtp_chk_reply { sock succ_code } {
  variable reply_code_str

  set r [ smtp_read $sock ]
  if {$r == -1} {
      return -code error "Socket closed by remote server"
  }

  set k [lindex [split $r " "] 0]
  if {$k != $succ_code} {
      return -code error [concat From SMTP server: $r\n$reply_code_str($k)]
  }
}

View solution in original post

Highlighted

Hi Joe,

great Job - it is working now!

Thanks a lot!

Best regards,

Andreas

Highlighted

You are great. I had same problem and couldn't figure out. took me 2 days and I found this, it works now. Thanks

Content for Community-Ad