Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I abort a SMTP send operation with Synapse for Delphi?

Tags:

email

delphi

At the moment I am testing Ararat Synapse to send e-mails in Delphi.

A local function creates a TSMTPSend and sends the e-mail.
How can I abort this operation? I have set a callback function assigned to SMTP.Sock.OnStatus to perform some status output.
When I want to abort the send progress, I thought I could use the TTCPBlockSocket of the TSMTPSend within the callback function because in this function I have no access to the TSMTPSend directly.

What I wanted to do looks basically like

MyCallBack(Sender: TObject; Reason: THookSocketReason; const Value: string);
begin
  if FCancelWasClicked then
  begin
    if Sender is TTCPBlockSocket then
      TTCPBlockSocket(Sender).StopFlag := True;
      // or TTCPBlockSocket(Sender).AbortSocket or CloseSocket
  end;
end;

But StopFlag shows no effect and AbortSocket/ CloseSocket lead to a StackOverFlow because the socket will then be pumping HR_CloseSocket messages endlessly.

Am I doing it wrong? Are there other options?

like image 473
Erik Virtel Avatar asked Feb 20 '13 11:02

Erik Virtel


1 Answers

Synapse provides a heartbeat function, which allows implementation of Cancel behaviour.

http://www.ararat.cz/synapse/doku.php/public:howto:heartbeat

Handle the OnHeartbeat event, set the HeartbeatRate property to the interval between heartbeats, and set the StopFlag to cancel the operation.

like image 88
tristan2468 Avatar answered Nov 20 '22 20:11

tristan2468