11-30-2014 04:26 PM
I can't get my router (887w) to send email via smtp requiring authentication. I gleaned that the applet would not work from another thread here, which I can't find now, and a tcl script must be used. Which appears correct as user:pass@mailserver and user@mailserver both can't connect via the applet method, and plain mailserver gets a return error.
Here is the simple script I'm trying to get working but get an error, I'm triggering it manually just to get it working:
::cisco::eem::event_register_none
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set mail_pre "Mailservername: me@mywork.com:mypass@mymailserver.com\n"
append mail_pre "From: router@mywork.com\n"
append mail_pre "To: me@mywork.com\n"
append mail_pre "Cc:\n"
append mail_pre "Subject: Route Table Change\n\n"
append mail_pre "ADSL may be down\n\n"
set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
if [catch {smtp_send_email $mail_msg} result] {
error $result $errorInfo
}
Error:
wrong 1st line format.
usage: Mailservername: <list of server names>
while executing
"smtp_send_email $mail_msg"
invoked from within
"$slave eval $Contents"
(procedure "eval_script" line 7)
invoked from within
"eval_script slave $scriptname"
invoked from within
"if {$security_level == 1} { #untrusted script
interp create -safe slave
interp share {} stdin slave
interp share {} stdout slave
..."
I have tried using only the mailserver FQDN and only the user@FQDN as well, but the same error.
The thread I based the script on was pretty old, did some syntax change since then or am I missing something else?
UPDATE (more info): I can telnet to the mailserver from the router fine, so it appears to just be a matter of passing the authentication correctly. The authentication in this case is a full email username and a password with special characters eg. "user@domain.com:p@$$". Is this not possible or am I misinterpreting the error?
Given I don't get some of the finer points of the script, it appears to be building a string to pass to the mail function and the first line has the correct syntax according the documentation.
IOS 15.2(4)M4
Solved! Go to Solution.
01-04-2015 10:46 AM
The error you get is still about the first line? I tested your script, and it works. Perhaps you're making changes to the script without reregistering it with EEM? If you make any changes, you need to do:
no event manager policy sendmail.tcl
event manager policy sendmail.tcl
Before those changes will take effect.
01-06-2015 08:02 AM
Another post just hit me with a clue bat. If GMail is forcing you to use TLS, then Tcl will not work. Tcl only supports unencrypted SMTP. This might be the cause of the 530 error. If not, then perhaps your password is wrong.
One workaround in the former case is to setup a local SMTP relay that can bridge the TLS gap between EEM and GMail.
12-17-2014 10:32 PM
The syntax looks okay provided you really do have a space between "Mailservername:" and the start of the server. Not having that space would be the only reason the error is thrown. That or you have some other weird characters in the script. It would be helpful if you posted the actual script file as an attachment.
12-19-2014 10:03 PM
I use tclsh to create the file because scp isn't working for me, but here is what more shows pasted out of the terminal.
Router#more eempol/sendmail.tcl
::cisco::eem::event_register_none
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set mail_pre "Mailservername: xxx@gmail.com:xxx@smtp.gmail.com\n"
append mail_pre "From: router@xxx.com.au\n"
append mail_pre "To: xxx@xxx.com.au\n"
append mail_pre "Cc:\n"
append mail_pre "Subject: Route Table Change\n\n"
append mail_pre "ADSL may be down\n\n"
set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
if [catch {smtp_send_email $mail_msg} result] {
error $result $errorInfo
}
Router#
There are no special characters in the redacted parts. I'm trying the gmail smtp in this iteration but have also tried the our hosted email smtp (but my password has special characters in that instance).
It is supposed to be "Mailservername" and not the name or ip of a mail server right (I did actually try a name there at one point but nothing changed)?
Version 15.2(4)M4, EEM 4.0
12-19-2014 10:23 PM
This doesn't help as there could still be a hidden character in the file that is not showing here. I would need the actual file to confirm.
The header should be Mailservername: SERVER
Where SERVER is your SMTP server and authn parameters. The single space character is needed between the colon and the start of the SMTP parameters. The error you're seeing can only be caused if the first line does not begin with Mailservername:
12-26-2014 04:58 PM
Here is the script. I did the redaction to the script before copying it off (and tested, it gives the same error), so it's a direct scp copy of what isn't working without post modification (except extension so I could upload it here).
Just to note, I have tried creating the script on the router via tclsh and now I have tried uploading one made with notepad++ and notepad, all with basically the same result (a less detailed error from the notepad one).
12-30-2014 08:04 PM
Perhaps there is a bug that is only in your version of code. Send the contents of tmpsys:/lib/tcl/smtp_lib.tcl from this router.
12-31-2014 09:38 PM
01-04-2015 10:46 AM
The error you get is still about the first line? I tested your script, and it works. Perhaps you're making changes to the script without reregistering it with EEM? If you make any changes, you need to do:
no event manager policy sendmail.tcl
event manager policy sendmail.tcl
Before those changes will take effect.
01-05-2015 05:38 PM
Oops... good call. I'm getting a new error after re-registering.
Translating "smtp.gmail.com"...domain server (139.130.4.4) [OK]
can't read "reply_code_str(530)": no such element in array
while executing
"smtp_send_email $mail_msg"
invoked from within
"$slave eval $Contents"
(procedure "eval_script" line 7)
invoked from within
"eval_script slave $scriptname"
invoked from within
"if {$security_level == 1} { #untrusted script
interp create -safe slave
interp share {} stdin slave
interp share {} stdout slave
..."
(file "tmpsys:/lib/tcl/base.tcl" line 50)
Tcl policy execute failed: can't read "reply_code_str(530)": no such element in array
I don't know what this error is.
01-05-2015 07:52 PM
This is a sendmail error that means authorization denied coming from your SMTP server. Talk to your admin to make sure the server will relay mail from your device.
01-06-2015 08:02 AM
Another post just hit me with a clue bat. If GMail is forcing you to use TLS, then Tcl will not work. Tcl only supports unencrypted SMTP. This might be the cause of the 530 error. If not, then perhaps your password is wrong.
One workaround in the former case is to setup a local SMTP relay that can bridge the TLS gap between EEM and GMail.
01-07-2015 06:12 PM
That makes sense. I couldn't tell from the error is was a rejection, connection failure, or script error. Gmail does require encryption... as does our hosted e-mail (which I wasn't using because it has more complicated user/pass strings that I thought might be mucking things up as well). Was hoping to avoid a local relay but oh well.
Thanks for the help!
01-07-2015 06:44 PM
Update, gmail fix. Got on the right track from this guys post.
use
Mailserver: aspmx.l.google.com
No username or password. And make sure you are sending to a gmail account, the server won't send to non-gapps.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide