I ran the following script on the MAC OSX version of TCL and it worked fine however it hangs on ActiveState TCL on a Windows 7 machine

proc send_simple_message {recipient email_server subject body} {
          package require smtp
          package require mime

    set token [mime::initialize -canonical text/plain -string $body]
          mime::setheader $token Subject $subject
          smtp::sendmessage $token \
                    -ports 587 \
                    -debug 1\
                    -username myAccount@gmail.com \
                    -password myPassword \
                    -recipients $recipient -servers $email_server
          mime::finalize $token
}

send_simple_message myAccount@gmail.com smtp.gmail.com \
    "This is the subject." "This is the message."

Any ideas what could be wrong on the Activestate system? (It's a fresh install of Activestate, downloaded it a couple days ago.)

UPDATE: I think it was freezing due to the corp firewall (I'll have to talk to someone about that.) HOWEVER While I can get farther when not going through the corp network it still doesn't deliver the message. I get the following debug info back:

Trying smtp.gmail.com...
<-- 220 mx.google.com ESMTP d8sm8712528ibl.1
--> EHLO ush10900dv (wait upto 300 seconds)
<-- 250-mx.google.com at your service, [32.178.65.125]
<-- 250-SIZE 35882577
<-- 250-8BITMIME
<-- 250-STARTTLS
<-- 250 ENHANCEDSTATUSCODES
--> STARTTLS (wait upto 300 seconds)
<-- 220 2.0.0 Ready to start TLS
--> EHLO ush10900dv (wait upto 300 seconds)
<-- 250-mx.google.com at your service, [32.178.65.125]
<-- 250-SIZE 35882577
<-- 250-8BITMIME
<-- 250-AUTH LOGIN PLAIN XOAUTH
<-- 250 ENHANCEDSTATUSCODES
--> MAIL FROM:<peddy@ush10900dv> SIZE=245 (wait upto 600 seconds)
<-- 530-5.5.1 Authentication Required. Learn more at

<-- 530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 d8sm8712528ibl.1
--> RSET (wait upto 0 seconds)
--> QUIT (wait upto 0 seconds)
handshake failed: resource temporarily unavailable
    while executing
"::tls::handshake $state(sd)"
    invoked from within
"smtp::sendmessage $token  -ports 587  -debug 1 -username username@gmail.com

The script is using the same credentials on both the MacOS machine and the Windows/Activestate machine, but it seem to be failing authorization? Any further ideas?

有帮助吗?

解决方案

It looks like you are not attempting to authenticate. On you Mac, your Tcl installation probably includes the SASL package from Tcllib and you may not have included it on your Windows machine. Not having SASL available is not an error as many people do not have to authenticate but you clearly require it. You can use the teacup utility to add the SASL package to your ActiveTcl install. teacup install SASL should do it. The package supports the LOGIN and PLAIN SASL mechanizms which are fine over a TLS link.

其他提示

Blocked by a firewall (or a general connectivity problem with reaching port tcp/587 of the remote machine)? I'd start with

set sock [socket $that_box 587]
gets $sock

in an interactive tclsh (tkcon is recommended). You should get the "HELO" string from the remote server in a reasonable time (may be a couple of seconds).

I spent several days trying to send email through both smtp.gmail.com and my local MS Exchange using authentication but without success. I finally managed to get it working using the code below. This procedure was run from withn PostgreSQL using pltclu.

I hope it helps at least one person.

create or replace function pgmail(text, text, text, text,text,text,text,text) returns int4 AS $$
package require smtp
package require mime
set mailfrom $1
set mailto $2
set mailsubject $3
set body $4
set myHost $5
set myPort $6
set myUname $7
set myUpassword $8


set token [mime::initialize -canonical "text/plain" -encoding "7bit" -string $body]
          mime::setheader $token Subject $mailsubject
          smtp::sendmessage $token \
            -servers [list $myHost] -ports [list $myPort]\
            -usetls true\
            -debug true\
            -username $myUname \
            -password $myUpassword\
            -queue false\
            -atleastone true\
            -header [list From "$mailfrom"] \
            -header [list To "$mailto"] \
            -header [list Subject "$mailsubject"]\
            -header [list Date "[clock format [clock seconds]]"]
          mime::finalize $token
return 1
$$ LANGUAGE pltclu;>

EDIT:

Make sure your mail client isn't set to check for new mail too often. If your mail client checks for new messages more than once every 10 minutes, your client might repeatedly request your username and password.

Follow the steps on Google Help Center and unlock your gmail.

If handshake problems persists it seems to be a Tcl's TLS implementation try upgrading and downgrading the package, if that don't work look if where tclsh.exe are placed, or tcl's library path, are a ssleay32.dll, and tell me about that.

another question, are you using a x64 distribution of windows 7?

This may be because of google security settings. please go to "https://www.google.com/settings/security/lesssecureapps" and make sure you enable Access for less secure apps. This worked for me.

Ravi.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top