Using SMTP Server in C#

Giganews Newsgroups
Subject: Using SMTP Server in C#
Posted by:  Joe Henrich (joe.henri…@gmail.com)
Date: Tue, 28 Sep 2004

I am trying to use the INDY 10 SMTP Server component with C# and I am
having an issue with how connections are being handled.  I believe it's a
mis-understanding on my part of how the SMTP server component works,
however, I can't seem to find any good documentation/samples of it that
help.  Anyway, I start by setting up and starting the server as follows:
/***********************Code Start **************************/
myServer = new Indy.Sockets.IndySMTPServer.SMTPServer();

myServer.ReceiveMode =     
Indy.Sockets.IndySMTPServer.SMTPReceiveMode.rmMessageParsed;    

myServer.OnReceiveMessageParsed +=new
Indy.Sockets.IndySMTPServer.TOnReceiveMessage(myServer_OnReceiveMessageParsed);

myServer.Active = true;
/**************** End of Code ***************************/

This seems to work, however, Once I connect, as soon as I send a
character(any character) to the server, it drops the connection.  Through
trial and error, I discovered that if I create an OnConnect procedure that
calls "DoRun()" on the context, I can get the helo command accepted and get
the Hello Response returned prior to a disconnection.  But, it still
disconnects.

So, noticing that the DoRun() returns a bool,  I put it into a while loop
such as while(AContext.DoRun());

This seemed to keep the connection alive, but, now, I keep getting "501
2.0.0 Invalid Syntax" on my "MAIL FROM:<joe.henriā€¦@gmail.com>" command.
Or, for any valid command for that matter.  If I send garbage commands
(like "aaa" or "bbb"), the server echos them back to me.

Also, I've tried assigning an "OnCommandMAIL" event, but it never fires,
nor does the OnDisconnect or OnException command.

Can anyone with some experience please explain to me what I'm missing?

Thank You,
        Joe Henrich

Replies