Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending MAIL command twice #13

Closed
OrangeDog opened this issue Mar 17, 2011 · 7 comments
Closed

Sending MAIL command twice #13

OrangeDog opened this issue Mar 17, 2011 · 7 comments

Comments

@OrangeDog
Copy link

When talking to a Python SMTP server (i.e. using stmpd.py), the MAIL command is sent twice, which is illegal SMTP. Nodemailer v0.1.9 and Node v0.4.2.

mailer.send_mail({
    //debug: true,
    html: 'Test',
    sender: 'foo@bar.com',
    subject: 'Subject',
    to: 'foo2@bar.com'
},function(err, success) {
    if (success) {
        util.log('[INFO] Email sent');
    }
    else {
        // this happens on every error, not just once per attempt
        util.log('[ERROR] Failed to send email: ' + JSON.stringify(err.message || err));
    }
});

generates the following output:

CONNECTION: 220 localhost Python SMTP proxy version 0.2
Connection established!
SEND:
"EHLO [127.0.0.1]\r\n"
RECEIVE:
"502 Error: command \"EHLO\" not implemented\r\n"
SEND:
"HELO [127.0.0.1]\r\n"
SEND:
"MAIL FROM:<foo@bar.com>\r\n"
RECEIVE:
"250 localhost\r\n"
SEND:
"MAIL FROM:<foo@bar.com>\r\n"
RECEIVE:
"250 Ok\r\n"
SEND:
"RCPT TO:<foo2@bar.com>\r\n"
RECEIVE:
"503 Error: nested MAIL command\r\n"
17 Mar 16:31:38 - [ERROR] Failed to send email: "503 Error: nested MAIL command"
@andris9
Copy link
Member

andris9 commented Mar 17, 2011

Should be fixed with 1034ae8 - if the server supported only HELO but not EHLO then all commands were sent twice.

@andris9 andris9 closed this as completed Mar 17, 2011
@OrangeDog
Copy link
Author

You are the fastest bug-fixer ever :)

@andris9
Copy link
Member

andris9 commented Mar 18, 2011

Thanks :)

@OrangeDog
Copy link
Author

Would this also have caused the callback to return twice, i.e. is the callback only supposed to return once?

@andris9
Copy link
Member

andris9 commented Mar 18, 2011

If the response for an EHLO command was erroneos (server didn't support it) then an additional HELO request was made. As there was a bug then the original "thread" (the EHLO one) didn't stop there and tried to continue anyway regardless of the error. Meanwhile HELO ended with success and started it's own separate command "thread" (actually it's not a thread but a callback chain or smth.), so as a consequence a set of two "threads" were sending matching commands to the same connection and thus fireing the callback function also not once but twice (one from the EHLO and one from the HELO thread).

In short - welcome to the wonderful world of callbacks and events :)

@OrangeDog
Copy link
Author

I've been in this world for a while.

@bvirlet
Copy link

bvirlet commented May 17, 2011

I'm encountering this issue. While trying to debug it I noticed that this merge seems to have removed the fix:
andris9@76ec625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants