S
Sven Groot
I have a Windows Service application that acts as if it's an SMTP server.
Outlook connects to this service, which is always running on the localhost.
This works fine most of the time.
However, sometimes it will no longer receive anything from Outlook.
Socket.Receive would block indefinitely (actually, Socket.Poll times out,
because that's what I'm using). Outlook sends it, because when I'm stepping
through the code with the debugger, everything works.
Although this happens rarely, there is one situation where this always
happens: when Outlook has more than one message to send in a single
send/receive action, it will always block after the second MAIL command. An
example SMTP transcript:
220 localhost welcomes you to SignalMailSMTP
EHLO qualityweb
250 OK
MAIL FROM: <[email protected]>
250 Mail from (e-mail address removed) accepted
RCPT TO: <[email protected]>
250 Recipient (e-mail address removed) accepted
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: "SignalMail" <[email protected]>
To: <[email protected]>
Subject: AEX Enter Long alert
Date: Sat, 27 Sep 2003 14:03:28 +0200
Message-ID: <000701c384ef$5d1ae640$9dfc3850@qualityweb>
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.4510
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Importance: Normal
..
250 OK
MAIL FROM: <[email protected]>
250 Mail from (e-mail address removed) accepted
The RCPT is never received. This has been reproduced on three separate
computers. Also, if you (or Outlook itself) retry too fast after this
failure, it will again fail, again at the RCPT command.
Now I can solve this by adding a delay (Thread.Sleep) but that's a highly
undesirable solution, as the exact delay value to make it work probably
depends on the speed of the computer it's running on. Also, it's a bit of a
hack.
Now I'm fresh out of ideas. It seems the message gets lost on the localhost
interface, but the question is, what can I do about it?
The code I'm using to receive:
Do
If mConnected.Poll(5000000, SelectMode.SelectRead) Then
BytesReceived = mConnected.Receive(Buffer)
Message &= Text.Encoding.ASCII.GetString(Buffer, 0, BytesReceived)
Else
mLogTransscript.Append("A timeout has occurred.")
mLogTransscript.Append(Environment.NewLine)
If Not mTransscript Is Nothing Then
mTransscript.WriteLine("A timeout has occurred.")
End If
mLogError = True
mState = SmtpState.Quit
Return Nothing
End If
Loop While Message.IndexOf(endSequence) = -1
Hopefully someone here can help.
Outlook connects to this service, which is always running on the localhost.
This works fine most of the time.
However, sometimes it will no longer receive anything from Outlook.
Socket.Receive would block indefinitely (actually, Socket.Poll times out,
because that's what I'm using). Outlook sends it, because when I'm stepping
through the code with the debugger, everything works.
Although this happens rarely, there is one situation where this always
happens: when Outlook has more than one message to send in a single
send/receive action, it will always block after the second MAIL command. An
example SMTP transcript:
220 localhost welcomes you to SignalMailSMTP
EHLO qualityweb
250 OK
MAIL FROM: <[email protected]>
250 Mail from (e-mail address removed) accepted
RCPT TO: <[email protected]>
250 Recipient (e-mail address removed) accepted
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: "SignalMail" <[email protected]>
To: <[email protected]>
Subject: AEX Enter Long alert
Date: Sat, 27 Sep 2003 14:03:28 +0200
Message-ID: <000701c384ef$5d1ae640$9dfc3850@qualityweb>
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.4510
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Importance: Normal
..
250 OK
MAIL FROM: <[email protected]>
250 Mail from (e-mail address removed) accepted
The RCPT is never received. This has been reproduced on three separate
computers. Also, if you (or Outlook itself) retry too fast after this
failure, it will again fail, again at the RCPT command.
Now I can solve this by adding a delay (Thread.Sleep) but that's a highly
undesirable solution, as the exact delay value to make it work probably
depends on the speed of the computer it's running on. Also, it's a bit of a
hack.
Now I'm fresh out of ideas. It seems the message gets lost on the localhost
interface, but the question is, what can I do about it?
The code I'm using to receive:
Do
If mConnected.Poll(5000000, SelectMode.SelectRead) Then
BytesReceived = mConnected.Receive(Buffer)
Message &= Text.Encoding.ASCII.GetString(Buffer, 0, BytesReceived)
Else
mLogTransscript.Append("A timeout has occurred.")
mLogTransscript.Append(Environment.NewLine)
If Not mTransscript Is Nothing Then
mTransscript.WriteLine("A timeout has occurred.")
End If
mLogError = True
mState = SmtpState.Quit
Return Nothing
End If
Loop While Message.IndexOf(endSequence) = -1
Hopefully someone here can help.