I’m working with Indy components in C++Builder 11.3 for our RAD Server application. I need to send emails through Gmail SMTP but keep getting authentication errors.
When I try to connect, I get the “Username and Password not accepted” error with a reference to Google’s bad credentials page. I’m using the correct email and password, so I think this might be related to SSL/TLS configuration.
Here’s my current implementation:
void __fastcall TEmailForm::SubmitButtonClick(TObject *Sender)
{
try
{
IdOpenSSLSetLibPath(L"C:\\ssl");
TIdSMTP *SmtpClient = new TIdSMTP(NULL);
SmtpClient->Host = "smtp.gmail.com";
SmtpClient->Port = 587;
SmtpClient->Username = "[email protected]";
SmtpClient->Password = "app_password";
SmtpClient->AuthType = satDefault;
TIdSSLIOHandlerSocketOpenSSL *SslHandler = new TIdSSLIOHandlerSocketOpenSSL(SmtpClient);
SslHandler->SSLOptions->SSLVersions << sslvTLSv1 << sslvTLSv1_1 << sslvTLSv1_2;
SslHandler->SSLOptions->Mode = sslmUnassigned;
SslHandler->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
SslHandler->SSLOptions->VerifyDepth = 0;
SmtpClient->IOHandler = SslHandler;
SmtpClient->UseTLS = utUseExplicitTLS;
TIdMessage *EmailMsg = new TIdMessage(NULL);
EmailMsg->From->Address = "[email protected]";
EmailMsg->Recipients->Add()->Address = "[email protected]";
EmailMsg->Subject = "Test Message";
EmailMsg->Body->Text = "Testing email functionality...";
try {
SmtpClient->Connect();
SmtpClient->Send(EmailMsg);
SmtpClient->Disconnect();
} catch (const Exception &e) {
LogMemo->Lines->Add("Connection Error: " + e.Message);
}
delete SmtpClient;
delete SslHandler;
delete EmailMsg;
}
catch (const Exception &ex)
{
LogMemo->Lines->Add("General Error: " + ex.Message);
}
}
I’ve tried different SSL library versions and checked my credentials multiple times. Could this be a TLS version compatibility issue with Gmail’s servers? Any suggestions for the correct SSL setup for 64-bit Windows would be helpful.