SMTPServer within a .Net application (General questions)
When I try to use the SMTPServer object within a .Net application the component accepts port 25 requests but just hangs. Below is some VB.Net sample code to generate the problem (it also happens when I use the Notifications Interface code as well). Hope someone can help.
Option Explicit On
Imports WODSMTPSERVERCOMLib
Public Class SMTPServerWrapper
Public WithEvents _SMTPServer As wodSmtpServerCom
Public Sub Setup()
_SMTPServer = New wodSmtpServerCom
_SMTPServer.Threads = ThreadTypes.FullThreads
_SMTPServer.Port = 25
_SMTPServer.GreetingMessage = SMTP Receiver
_SMTPServer.GoodbyeMessage = SMTP Receiver
_SMTPServer.Start()
End Sub
Protected Sub MailReceived(ByVal User As WODSMTPSERVERCOMLib.SmtpUser, ByRef Action As WODSMTPSERVERCOMLib.SmtpActions) Handles _SMTPServer.MailReceived
Debug.WriteLine( Got mail )
End Sub
end class
Re: SMTPServer within a .Net application
Derek,
who hangs, server or the client? Can you be more specific?
Kreso
Re: SMTPServer within a .Net application
A telnet on port 25 accepts the connection, but instead of a greeting message, I get nothing.
Re: SMTPServer within a .Net application
Derek,
hmm, this is so obvious that it should work. Do you have some firewall software (such as ZoneAlarm) running, perhaps that's the one answering port 25?
Can you zip that project and send it to techsupport@weonlydo.com, I'd like to try it out here.
Kreso
Re: SMTPServer within a .Net application
The following code has the same issue
Dim SMTPS As New wodSmtpServerCom
SMTPS.Start()
System.Threading.Thread.Sleep(100000)
Execute the compiled application and then telnet to the local host (telnet 127.0.0.1 25) and the connection is made, but nothing happens. So it's fairly fundamental.
The Visual Basic 6.0 example works fine, though.
Derek
Re: SMTPServer within a .Net application
It's on its way. Sending the really basic example that still fails. Not running a firewall on the desktop. Same occurs on two completely different systems as well.
Re: SMTPServer within a .Net application
Derek,
this sample with 'Sleep' call you sent obviously fails becuase you call Sleep. This makes main thread (and this is where wodSmtpServer lives in) is halted, so wodSmtpServer cannot process any messages.
Can you change it so you give wodSmtpServer thread running?
Kreso
Re: SMTPServer within a .Net application
I've replaced the sleep line with:
Do While True
Debug.Write( X )
Loop
Still does the same thing. If its event driven it shouldn't care about the sleep though, should it?
Derek
Re: SMTPServer within a .Net application
Your loop still doesn't allow messages to be processed, since you're taken over complete thread. Adding DoEvents could help.
As for being event driven - if it lives in same thread, you can't take it for yourself all the time. You have to do your code and get out to windows message pump as soon as you can.
Kreso
Re: SMTPServer within a .Net application
Application.Doevents is only available for Forms based projects. As this is a command line project (and the final project a service) do you have another suggestion?
Re: SMTPServer within a .Net application
Derek,
umm. No. You must somehow allow wodSmtpServer to do processing. You could create hidden window and implement message pump on it, not sure if it's possible in VB.NET
I know this sounds strange that you can't run it in console app, but you must understand this is a DLL, not separate EXE. It lives in your process space, and in the same thread you assign to it.
Kreso
Re: SMTPServer within a .Net application
Oh dear. I'm not sure I can implement a forms based class within a managed code service, so I may be screwed here. This is what I bought the component for. I'll see what I can work out.
Derek