2

I have a strange issue sending an email via gmail. I am using Delphi 7 and Indy 9 working on Windows 7 Professionel 32-bit on a VirtualBox (4.2)

Since Indy 9 doesn't support TLS out of the box I have to send the STARTTLS command myself.

This works just well with a small test mail. A regular mail with an attachment causes the VirtualBox to completly crash. No Windows blue screen.

I have already found a workaround but it seems quite dirty. If I add the IdSSLOpenSSL.pas from the Delphi source and add a Sleep(5); to the Send function it works

function TIdSSLIOHandlerSocket.Send(var ABuf; ALen: integer): integer;
begin
  // 13.12.2012 fix timing
  Sleep(5);

  if fPassThrough then begin
    result := inherited Send(ABuf, ALen);
  end
  else begin
    result := SendEnc(ABuf, ALen);
  end;
end;

Is there a better way to fix this issue?

In case you need the Code to setup the IOHandler

sslIOHandler                   := TIdSSLIOHandlerSocket.Create(nil);
sslIOHandler.SSLOptions.Method := sslvTLSv1;
sslIOHandler.PassThrough       := True;
IdSSLOpenSSLHeaders.Load;
smtpClient.Username            := tbUsername.Text;
smtpClient.Password            := tbPassword.Text;
smtpClient.AuthenticationType  := atLogin;
smtpClient.IOHandler           := sslIOHandler;
smtpClient.Connect(C_TIMEOUT);
smtpClient.SendCmd('STARTTLS');
sslIOHandler.PassThrough := False;
smtpClient.Authenticate();
fuchs777
  • 993
  • 1
  • 14
  • 30
  • 2
    Are there any reasons to use dino-ages old, unsupported, Indy 9, while there is free Indy 10, and a lot of other components? – Nickolay Olshevsky Dec 13 '12 at 17:05
  • 1
    After sending a successful `STARTTLS` and establishing the TLS session, you need to re-issue a new `HELO`/`EHLO` command to discover the server's new capabilities, which may have changed due to activating TLS. – Remy Lebeau Dec 14 '12 at 01:07
  • @ Nickolay, we have too much applications running on this setup to migrate to Indy 10 in resonable time, anyway its not my desicion @Remy Lebeau, I don't see what that should help with an obvious timing problem in the ssl handler, but thanks for the hint – fuchs777 Dec 14 '12 at 07:49

1 Answers1

1

Since noone seems to have a solution for this and upgrading to Indy 10 is no option (too many projects are involved) I found a different library to handle smtp with tls...

Now I use Synapse which does not interfere with Indy 9 and does just what I expected.

http://synapse.ararat.cz/doku.php/public:howto:smtpsend

Hopefully this helps others with the same problem.

fuchs777
  • 993
  • 1
  • 14
  • 30