Saturday, July 29, 2006, 11:48, Max Terentiev wrote: > Helo, > > What is a best event for starting new Smtp session (e.g. > start sending next message after previous is sent or aborted)?
Use OnRequestDone(). Check from there if the request was Abort. What I do is that I build a state machine in the OnRequestDone() event and call the appropriate method from there. When I build a mass mailer (that sends more than one message at a time), I check after the Data() and Abort() requests are completed if the component is connected. If it is connected, I just call the Reset() method to start a new transaction within the same session; if it is not connected, I call the Connect() method to start a new session. The state machine then continues as usual in both cases. Note that you also need to check for errors before checking the states. > I was try to Use OnSessionClosed or OnStateChange events > (in OnStateChange i wait for SmtpCli->State==smtpReady and > Smtp->>CtrlSocket->State=wsClosed). Those events are designed for progress indicators. The OnRequestDone is called after every request has completed (and a response has been received from the server), whether it failed or succeeded. > After sending message (or getting smtp protocol error during sending > message) I ALWAYS Call SmtpCli->Abort() and wait in OnStateChange > until connection closed and component is ready. After it I prepare next > message and call SmtpCli->Connect(), etc. Do not call Abort(), call instead Reset(). This will reset the server state ("RSET" SMTP command) so that you can start a new transaction. In the OnRequestDone() handler (and state machine), look for the response of Reset and treat it the same as a response from Helo() (since the server will engage the same state at that point). Only call Abort() when you want to stop all sending (like if the user decided to abort a mass mailing). Abort will not close the connection gracefully, but will just shutdown the socket and reset the component, which may not happen immediately. So the state changes, while the socket may still be waiting to close. > Why I receive errors 1-4 ?? Maybe I must do something special ? How i > can ensure what connection is 100% closed and component 100% ready for > next > session ? Check the SmptCli.Connected property before calling the Connect() method. Do not depend on the SmtpCli.State property, as the server could have dropped the connection before the component noticed; but the SmtpCli.Connected property is an interface to the underlying TWSocket component. dZ. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be