I’m using the Indy Components in C++ Builder 11.3 to attempt to send an email from within our Rad Server project. For testing purposes I wrote the 64 bit code below and I’m getting an error that has been addressed before by Remy in his answer to SSL Negotiation in Delhi 11.
I ported the code exactly from Remy’s post, with the exception of the C++ caveats. I’m getting a Bad Credentials exception. It seems to be an SSL/TLS issue.
Below is the code and two images with the exceptions, one exception is referenced in the code and has to do with what appears to be property assignment timing.
Does anyone see anything wrong with this code and/or help to provide an answer as to why the errors are happening ? If someone believes it is an SSL/TLS issue, where can I find the correct versions for 64 bit Windows/Windows Server 2019?
//---------------------------------------------------------------------------
void __fastcall TMainForm::SendBtnClick(TObject *Sender)
{
try
{
// Point to SSL
IdOpenSSLSetLibPath(L"C:\openssl");
// Set up SMTP
TIdSMTP *IdSMTP = new TIdSMTP(NULL);
IdSMTP->Host = "smtp.gmail.com";
IdSMTP->Port = 587;
IdSMTP->Username = "[email protected]";
IdSMTP->Password = "my_password_phrase";
IdSMTP->AuthType = satDefault;
// Set up SSL/TLS
TIdSSLIOHandlerSocketOpenSSL *IdSSL = new TIdSSLIOHandlerSocketOpenSSL(IdSMTP);
IdSSL->SSLOptions->SSLVersions << sslvTLSv1 << sslvTLSv1_1 << sslvTLSv1_2;
IdSSL->SSLOptions->Mode = sslmUnassigned;
IdSSL->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
IdSSL->SSLOptions->VerifyDepth = 0;
IdSMTP->IOHandler = IdSSL;
// Had to move the IdSMTP TLS property below the IOHandler as
// it appears that in C++ you should have your IOHandler set
// up before setting the IdSMPT property, or you will get,
// "SSL IOHandler is required for this setting" exception.
IdSMTP->UseTLS = utUseExplicitTLS;
// Set up Message
TIdMessage *IdMessage = new TIdMessage(NULL);
IdMessage->From->Address = "[email protected]";
IdMessage->Recipients->Add()->Address = "[email protected]";
IdMessage->Subject = "Test Email";
IdMessage->Body->Text = "Super Cool Test...";
try {
IdSMTP->Connect();
IdSMTP->Send(IdMessage);
IdSMTP->Disconnect();
} catch (const Exception &e) {
ErrorMemo->Lines->Add("[Connect Exception]: " + e.Message);
}
// Tidy up
delete IdSMTP;
delete IdSSL;
delete IdMessage;
ErrorMemo->Lines->Add("No leaks");
}
catch (const Exception &exception)
{
ErrorMemo->Lines->Add("[Method Exception]: " + exception.Message);
}
}
Tried using the design time component properties and very little code to what you see above. Also I’ve installed several different binary versions of the SSL packages from searches, etc., but can’t seem to get it working.