Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi 10, email program


This question is not answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jul 11, 2017 6:51 AM Last Post By: Jim Sawyer
Jim Sawyer

Posts: 214
Registered: 1/3/10
Delphi 10, email program  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2017 8:04 AM
I'm starting a new thread since that last one if getting so massive.
I'm trying to use Windows 10, Delphi, Indy to design email
capability into my Veterinary Management package. My code
currently is

procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
begin
  with idSMTP do
  begin
    Host := LowerCase( txtServer.text );
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    if ( cbSSL.Checked ) then
      UseTLS := utUseExplicitTLS
    else
      UseTLS := utUseImplicitTLS;
    Port := Round( numPort.Value );
    // AuthType := satDefault;
    AuthType := satSASL;
    Password := txtPassword.Text;
    UserName := txtFrom.Text;
    ValidateAuthLoginCapability := false;
  end;
  // setup idMessage parameters
  with idMessage do
  begin
    From.Address := txtFrom.Text;
    Recipients.EMailAddresses := txtTo.Text;
    CCList.EMailAddresses := txtCC.Text;
//    BCCList.EMailAddresses := txtBC.Text;
    Subject := txtSubject.Text;
    Body.Text := memoBody.Text;
  end;
  // check if receipt confirmation is required
  if cbConfirm.Checked then
    idMessage.ReceiptRecipient.Text := txtFrom.Text;
  // send Message
  try
    btnSendEmail.Enabled := false;
    idSMTP.Connect;
    try
      // idSMPT.Authenticate
      idSMTP.Send( idMessage );
//      Result := true
    except
      on E : Exception do
        ShowMessage( 'Connection.Failed' );
    end;
  finally
    // disconnect from server
    if idSMTP.Connected then
      idSMTP.Disconnect;
    btnSendEmail.Enabled := true;
  end;
end;
 
procedure TfrmTesting.FormActivate(Sender: TObject);
begin
  txtServer.Text := 'smtp.gmail.com';
  txtPassword.Text := 'minnow*Bucket22';
  txtFrom.Text := 'jimsawyer222@gmail.com';
  txtTo.Text := 'jim.sawyer@verizon.net';
  txtSubject.Text := 'Testing';
  cbSSL.Checked := true;
  numPort.Value := 465;
  memoBody.Text := 'Testing email.';
  Left := Screen.Width div 2 - Width div 2;
  Top := Screen.Height div 2 - Height div 2;
end;


My current questions are

1) Do I need 32 bit and/or 64 bit versions of sslLeahy and libeasy dll's and
if so, do they need to be "installed" or just dropped into the directory? And
since there appear to be several versions, do I need a specific version
for Windows 10, Delphi 10 and where should I download them from?

2) What does it mean to "ping" an address, and how do I go about it?

3) Any other advise?

Thanks,
Jim Sawyer
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Delphi 10, email program
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2017 1:29 PM   in response to: Jim Sawyer in response to: Jim Sawyer
Jim Sawyer wrote:

if ( cbSSL.Checked ) then
UseTLS := utUseExplicitTLS
else
UseTLS := utUseImplicitTLS;

If the user does not choose to enable SSL, why are you setting UseTLS
to utUseImplicitTLS? If the user does not want to use SSL/TLS, you
should be setting it to utNoTLSSupport instead.

utUseImplicitTLS performs an SSL/TLS handshake as soon as the socket is
connected, before any protocol-level (ie SMTP) data is exchanged.

utUseExplicitTLS performs a handshake only after asking the server for
permission first (ie using the SMTP 'STARTTLS' command).

// AuthType := satDefault;
AuthType := satSASL;
Password := txtPassword.Text;
UserName := txtFrom.Text;

Note that TIdSMTP's UserName and Password properties are only used when
AuthType is satDefault. When AutType is satSASL instead, you need to
populate the TIdSMTP.SASLMechanisms collection with SSAL components,
and then assign a TIdUserPassProvider component to the SASL components.

try
btnSendEmail.Enabled := false;
idSMTP.Connect;
try
// idSMPT.Authenticate
idSMTP.Send( idMessage );
// Result := true
except
on E : Exception do
ShowMessage( 'Connection.Failed' );
end;
finally
// disconnect from server
if idSMTP.Connected then
idSMTP.Disconnect;
btnSendEmail.Enabled := true;
end;

The disabling of the button belongs above the try block, and the call
to Disconnect() belongs in a separate nested try/finally block. I
showed you that earlier:

btnSendEmail.Enabled := false;
try
  try
    idSMTP.Connect;
    try
      // idSMPT.Authenticate
      idSMTP.Send( idMessage );
      //      Result := true
    finally
      // disconnect from server
      idSMTP.Disconnect;
    end;
  except
    on E : Exception do
      ShowMessage( 'Connection.Failed' );
  end;
finally
  btnSendEmail.Enabled := true;
end;


txtServer.Text := 'smtp.gmail.com';
txtPassword.Text := ...;
txtFrom.Text := ...;

I hope you did not just post real credentials in a public forum!

1) Do I need 32 bit and/or 64 bit versions of sslLeahy and libeasy
dll's

Yes, if you are using TIdSSLIOHandlerSocketOpenSSL, and not some other
SSL-based IOHandler.

and if so, do they need to be "installed" or just dropped into
the directory?

They don't need to be "installed", but they can be placed anywhere on
the system's search path, though the app directory is the best place.
Unless you call's Indy's IdOpenSSLSetLibPath() function before opening
any SSL connections, in which case you can use any folder you want.

And since there appear to be several versions, do I need a specific
version for Windows 10, Delphi 10 and where should I download them
from?

Just use the latest OpenSSL 1.0.2x version from
http://indy.fulgan.com/SSL/.

2) What does it mean to "ping" an address, and how do I go about it?

If you have to ask, you shouldn't be using it. Actually, you shouldn't
be using it anyway. Pinging an address simply tells you whether the
address is reachable by your network connection, but it doesn't tell
you what services are listening at the address, if any. The best way
to find out is to simply connect and handle any error that may occur.

--
Remy Lebeau (TeamB)
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: Delphi 10, email program  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2017 6:51 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I am still struggling with this routine. My code is currently as follows:

procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
begin
  with idSMTP do
  begin
    Host := LowerCase( txtServer.text );
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    if ( cbSSL.Checked ) then
      UseTLS := utUseExplicitTLS
    else
      UseTLS := utNoTLSSupport;
    Port := Round( numPort.Value );
    // AuthType := satDefault;
    AuthType := satSASL;
    Password := txtPassword.Text;
    UserName := txtFrom.Text;
    ValidateAuthLoginCapability := false;
  end;
  // setup idMessage parameters
  with idMessage do
  begin
    From.Address := txtFrom.Text;
    Recipients.EMailAddresses := txtTo.Text;
    CCList.EMailAddresses := txtCC.Text;
//    BCCList.EMailAddresses := txtBC.Text;
    Subject := txtSubject.Text;
    Body.Text := memoBody.Text;
  end;
  // check if receipt confirmation is required
  if cbConfirm.Checked then
    idMessage.ReceiptRecipient.Text := txtFrom.Text;
  btnSendEmail.Enabled := false;
  // send Message
  try
    idSMTP.Connect;
    try
      // idSMPT.Authenticate
      idSMTP.Send( idMessage );
//      Result := true
    except
      on E : Exception do
        ShowMessage( 'Connection.Failed' );
    end;
  finally
    // disconnect from server
    if idSMTP.Connected then
      idSMTP.Disconnect;
    btnSendEmail.Enabled := true;
  end;
end;


I have downloaded dlls and currently have on the 32 bit location the files

libeay32.dll 1337kb
ssleay32.dll 330kb

In the 64 bit executable location I've accumulatedl the files

libeay32.dll 2213kb
libeay64.dll 1364kb
ssleasy32.dll 376kb
ssleasy64.dll 361kb

I still have the same

EIdConnClosedGracefully

error with both the 32 bit and 64 bit executables. I'm having
a hell of a time translating your suggestions into actual code.
I guess I need to see an example of my code modified
such that it works. I'm also not sure I have the correct dlls
in the correct place.

I appreciate your help.

Thanks,
Jim Sawyer
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02