Hello, I've tested one of my ideas for making SmtpCli working for me now. I've constructed a thread which will do the sending of the mail and thus does a thread attach/detach and has its own message loop.
It also knows the threadid of the main program so it posts a message to it when the thread's execute is done either by successfully sending the mail or because some error occured. (okay, I should add the errorcode to the message, just got this idea but okay...). The thread also has a Cancel method which sends a special message to the thread which also makes it leave his message loop and does a abort on the control socket of the smtpcli and on the smtpcli. The one sending the e-mail fires a timer which when occurring will call this cancel method. If the mail sending was faster than the timer the timer is freed. I've tested this with a working e-mail server and a wrong host name. Is seemed to work, but I'd like to have some expert's opinion if this is good (or at least okay) practice or not, before I'm running into severe trouble. I'll slightly enhance it and test it tomorrow at work. This is the execute (where mainform is the VCL mainform of the test app.): procedure TThreadedMail.Execute; var msg:TMsg; begin mainform.SmtpCli.ThreadAttach; mainform.SmtpCli.CtrlSocket.MultiThreaded:=true; mainform.SmtpCli.Connect; msg.message:=0; while GetMessage(Msg, 0, 0, 0) do begin if (msg.message = wm_mailcancel) then break; TranslateMessage(Msg); DispatchMessage(Msg); end; if (Msg.message = wm_mailcancel) then begin try mainform.SmtpCli.CtrlSocket.Abort; mainform.SmtpCli.Abort; except end; end; mainform.SmtpCli.ThreadDetach; PostThreadMessage(mainthread, wm_mailende, 0, 0); end; Greetings Markus -- 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