Menu

#782 smtp or socket issue causes error 400 in Windows XP Pro

open
smtp (24)
7
2006-08-30
2006-02-13
Robert Joy
No

I thought I had submitted this back in 2005 but I do
not see it in the bug database so I am sumbitting
again.

I am using tcllib mime and smtp to send email from a
tcl tool. Unfortunately, it seems that a socket error
is being thrown if the body size gets beyond around
10KB. I'm unsure if it's a socket issue or a tcllib
issue. It seems to be consistent as I have tried this
with 3 different body texts. I already sumbitted this
to ActiveState and they referred me over here. Please
see the submission on ActiveStates bug system. The
bug ID is 42067. I have upload several files there. I
would really appreciate it if you guys could take a
look at this.

Thanks,
Robert Joy

Discussion

  • Pat Thoyts

    Pat Thoyts - 2006-04-21

    Logged In: YES
    user_id=202636

    The AS bug: http://bugs.activestate.com/show_bug.cgi?id=42067

     
  • Pat Thoyts

    Pat Thoyts - 2006-04-21

    Logged In: YES
    user_id=202636

    I believe this is actually a problem on your server. The
    script provided works fine (although you should add the
    following lines to get the To and From headers added)
    set from "\"$fullname\" <$emailaddr>"
    mime::setheader $token From $from
    mime::setheader $token To $to

    I have tried this using the files you attached to the
    ActiveState bug on a Microsoft SMTP server and on Postfix
    (on Linux) and both worked ok. If you want to test this
    yourself locally I suggest you add -debug 1 to the options
    for smtp::sendmessage. This gets it to record the SMTP
    conversation to stderr.
    You might also try the sample smtp server that is part of
    tcllib itself. If you start the example server (wish
    tcllib\examples\smptd\tk_smtpd) and set the port number to
    25 you can ue your script and send mail to localhost as the
    server. This way you can see both sides of the conversation.
    It's possible that your server is using the SIZE extension
    and limiting SIZE to something very small.

    I am going to close this as works for me - but reopen if you
    have more information to add.

     
  • Pat Thoyts

    Pat Thoyts - 2006-04-21
    • assigned_to: mrose --> patthoyts
    • status: open --> closed-works-for-me
     
  • Robert Joy

    Robert Joy - 2006-04-21
    • status: closed-works-for-me --> open-works-for-me
     
  • Robert Joy

    Robert Joy - 2006-04-21

    Logged In: YES
    user_id=1373320

    Ok, seems I left out something. I am sending the email
    through an external email server owned by a reputable
    hosting company. I believe this may effect the outcome. So
    I am re-opening this report and adding some new info. I
    have attached a file that contains the smtp dump after
    turning on the -debug flag, a code snippet used to send
    the message and the tcl result error. Also, the mail gets
    sent but it's truncated to something less than 10KB.

    Also, the machine that is running my program is the same
    machine that I use for my personal email client
    (Thunderbird). It works just fine for sending large email
    bodies.

    Please let me know what you think. You might also try
    sending a message to an external server and see what you
    get. Please make sure to use a large file and ensure that
    received file is approximately the same size. My test file
    was 52KB.

    Thanks Patt

     
  • Robert Joy

    Robert Joy - 2006-04-21

    New error info

     
  • Robert Joy

    Robert Joy - 2006-04-21

    Logged In: YES
    user_id=1373320

    Oh, one more thing, the path you gave to the example smtp
    server does not exist on my install of ActiveTcl 8.4.11.2

     
  • Pat Thoyts

    Pat Thoyts - 2006-04-21

    Logged In: YES
    user_id=202636

    Using information contained in your attachment I have sent
    myself the mime.tcl file (108K) using your script on a
    Windows XP machine and sending via your server. In all cases
    I have got the full file. I'll separately mail you some
    extra bits.

     
  • Nobody/Anonymous

    Logged In: NO

    I get the same error when sending mail attatchments bigger
    than 6-7 kb. The smtp package stops the base64 encoded
    part, sends a newline and a dot, then RSET and QUIT. (no
    ending boundry)

    The error message is "400: error writing "sock244": invalid
    argument"

    Here, a ethereal dump of the end of the conversation with
    mail server:
    <dump>
    dWJ0eXBlL1RydWVUeXBlPj4KZW5kb2JqCjI1IDAgb2JqCjw8L1R5cGUvRW5j
    b2RpbmcvQmFzZUVu
    Y29kaW5nL1dpbkFuc2lFbmNvZGluZy9EaWZmZXJlbmNlc1sKMS9qL
    .
    RSET
    QUIT
    250 198182198 mailfe02 Message accepted for delivery
    250 SMTP state reset
    221 mailfe02.swip.net SMTP closing connection
    </dump>
    Looks like smtp tries to send rest of the data, but
    allready has closed the connection.
    Rgds.
    Jesper

     
  • Nobody/Anonymous

    Logged In: NO

    In addition to my previously post.
    Just tested the setup thru sockspy, and the error didnt
    occur. This could look like some socket issue in the smtp
    package code.

    Rgds
    Jesper

     
  • Robert Joy

    Robert Joy - 2006-05-15

    Logged In: YES
    user_id=1373320

    This issue was resolved for me by Pat Thoyts. It turned
    out to be an problem with the TCLs standard socket
    implementation. Here's the solution:

    One last thing I thought of is there is an alternative
    socket implementation for Tcl on windows - the iocpsock
    extension provides a socket2 command. It was written as a
    performance enhanced socket layer and uses the winsock
    APIs rather than the BSD socket APIs. There is a slight
    chance this might produce a different result for you. You
    would use it by doing:

    package require Iocpsock
    interp alias {} socket {} socket2

     
  • Robert Joy

    Robert Joy - 2006-05-15
    • status: open-works-for-me --> closed-works-for-me
     
  • Robert Joy

    Robert Joy - 2006-08-30

    Logged In: YES
    user_id=1373320

    This issue was not resolved. It appeared that it was
    working because I move from the standard socket to the
    iocpsock package which allowed a larger portion of the
    email to be sent before something went wrong.

    I did some more testing and here's what I discovered:

    I went into the the smtp package and disabled the trf
    package call. This allowed me to send large emails and
    attachments but I was not happy with this solution so I
    poked around some more and found that the tls package was
    not installed on my system. I assumed everything needed
    was there since I'm using ActiveTcl from ActiveState.
    Those guys are usually pretty good about including
    everything but I've since been informed that the package
    was excluded from ActiveTcl due to export restrictions on
    the crypt stuff.

    Second, if I send an email WITH "-usetls true" the mail
    sends just fine (this is how Pat Thoyts was sending his
    emails). However, when I send emails with "-usetls false"
    it fails miserably and I get the dreaded iocpsock/sock
    error!

    I'd like to see if you can send a large email soemthing in
    the neighborhood of 1MB with the -usetls set to false.
    There's obviously still something wrong with the way the
    smtp package is handling the trf stuff.

     
  • Robert Joy

    Robert Joy - 2006-08-30
    • priority: 5 --> 7
    • status: closed-works-for-me --> open
     
  • Mark Garvey

    Mark Garvey - 2006-11-03

    Logged In: YES
    user_id=1183601

    FWIW, this bug has just appeared after an upgrade to tcllib-1.9
    tcllib-1.8 was/is working fine so I'll stick with it for the moment.
    System Win XP PRO SP2, iocpsock does not improve the situation. (tcl 8.4.13)
    Code is as follows:

    set token [mime::initialize -canonical text/plain -string $body]
    catch {smtp::sendmessage $token \
    -recipients $recipient\
    -header [list From $from]\
    -header [list To $recipient]\
    -header [list Subject $subject]\
    -servers $email_server -usetls 0} error
    mime::finalize $token