Send email with Indy components

Hi all,

I am trying to get email sending in my application to work but keep getting errors

Could someone please have a look at what I’m doing and give me some guidance

A Gmail account is the target email host.

Please note that the message, along with sender & receiver details are loaded in a separate procedure
Using Delphi 12

Uses
    IdSMTP1: TIdSMTP;
    IdMessage1: TIdMessage;
    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
    IdAntiFreeze1: TIdAntiFreeze;

The open SSL library version is openssl-1.0.2u-x64_86-win64

The files ssleay32.dll and libeay32.dll I have copied across to the same folder as the application exe

My code is,

procedure TEmail_Frm.Send_BtnClick(Sender: TObject);
begin
  /// ////////  Configure the SMTP component
  IdSMTP1.Host := 'smtp.gmail.com';
  IdSMTP1.Port := 587;
  IdSMTP1.Username := Grant_Brown_Txt;
  IdSMTP1.Password := Brownes_Block_House_Password;
  IdSMTP1.AuthType := satDefault;
  /// //////// Configure the SSL component
  /// ssleay32.dll and libeay32.dll located in same folder as application exe
  IdSSLIOHandlerSocketOpenSSL1.Host := 'smtp.gmail.com';
  IdSSLIOHandlerSocketOpenSSL1.Port := 587;
  /// //////// Configure the Message component
  IdMessage1.From.Name := Current_Sender_User_Name;
  IdMessage1.From.Address := Brownes_Block_House_Email_Address;
  IdMessage1.Subject := Trim(Subject_EditBx.Text);
  IdMessage1.Priority := mpHighest;
  IdMessage1.Organization := Brownes_Block_House_Name;
  IdMessage1.ContentType := 'text/plain';
  /// //////// send the email message
  try
    IdSMTP1.Connect;
    IdSMTP1.Send(IdMessage1);
  finally
    IdSMTP1.Disconnect();
  end;

  Enable_Disable_Button(Send_Btn, False);
end;

the latest exception message is,

Project Soluar_Interface_Rev01.exe raised exception

  • class EIdOSSLCouldNotLoadSSLLibrary with message ‘Could not load SSL library.’*

Help please as I’m at my wits end with this

Many many thanks in advance
Grant

where have you put the indy ssl libraries?

Use can use Overbyte ICS SSL component TSslSmtpCli.
see this page: ICS Download - Overbyte

Hi Grant,

Are you aware that using a Gmail account as the host for SMTP, you can’t just use the normal account password. You’ll need to go into your account settings and create an “App Password”

John

President @Geoff has a Github repo for GMail … GmailAuthSMTP/README.md at master · geoffsmith82/GmailAuthSMTP · GitHub

1 Like

And @ianbarker covered Gmail in the 30/30 webinars

1 Like

Recommend using GitHub - JPeterMugaas/TaurusTLS: OpenSSL 1.1.1 and OpenSSL 3.x support for Indy - Internet Direct so that you can use the latest OpenSSL dll’s.

3 Likes

There is a TaurusTLS (beta) entry in GetIt now.

Google do not recommend App passwords and IIRC they are looking to stop using them (I could be misremembering, I’ve done a lot of weird stuff in the webinars and it’s starting to bend my brain).

Here’s their app passwords wording: Sign in with app passwords - Gmail Help

You’re much better using @Geoff 's excellent GitHub repo and considering TaurusTLS too for a complete modern and more secure solution.