Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Email with Indy


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


Permlink Replies: 7 - Last Post: Jul 3, 2017 11:37 AM Last Post By: Remy Lebeau (Te...
Jim Sawyer

Posts: 214
Registered: 1/3/10
Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 29, 2017 3:49 PM
I am using the following code:

procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
var
sHostStr: String;
begin
sHostStr := txtServer.Text;
with idSMTP do
begin
sHostStr := LowerCase( sHostStr );
if sHostStr = 'xtra.co.nz' then
Host := 'send.' + sHostStr
else
Host := 'SMTP.' + sHostStr;
IOHandler := IdSSLIOHandlerSocketOpenSSL1;
if ( txtServer.Text = 'smtp.gmail.com' ) then
begin
UseTLS := utUseExplicitTLS;
Port := 587;
end
else
begin
if ( sHostStr = 'xtra.co.nz' ) then
begin
UseTLS := utUseImplicitTLS;
Port := 465;
end
else
begin
UseTLS := utUseExplicitTLS;
Port := 25; // smpt usually runs on this port;
end;
end;
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;
{ code }

I am using gmail to send from. I get the following error:

EIdSocketError with Message 'Socket Error #11011' host not found

I have no idea how to resolve that error and I'm hoping someone can
examine this code and see what I have wrong.

After I get this working, I also need someone to tell me how to
modify it to send HTML. I can generate the HTML message,
but I need to know how to send it.

Thanks,
Jim Sawyer
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 29, 2017 6:14 PM   in response to: Jim Sawyer in response to: Jim Sawyer
Jim Sawyer wrote:
sHostStr := LowerCase( sHostStr );
if sHostStr = 'xtra.co.nz' then
Host := 'send.' + sHostStr
else
Host := 'SMTP.' + sHostStr;

Why are you doing any of that? The user should enter the hostname exactly as it is registered in DNS. Don't mess around with it. What if the user's SMTP server does not actually begin with 'smtp'? You would corrupt the hostname, which would easily explain the error you are getting. Just use the hostname as the user entered it, and let DNS handle the rest.

if ( txtServer.Text = 'smtp.gmail.com' ) then
begin
UseTLS := utUseExplicitTLS;
Port := 587;
end
else
begin
if ( sHostStr = 'xtra.co.nz' ) then
begin
UseTLS := utUseImplicitTLS;
Port := 465;
end
else
begin
UseTLS := utUseExplicitTLS;
Port := 25; // smpt usually runs on this port;
end;
end;

You shouldn't be doing any of that, either. Don't base your configuration on the hostname like that. There are thousands of SMTP servers in the world, and they support implicit or explicit TLS in their own ways, You are best off letting the user specify the desired port and TLS settings, don't assume them.

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

Note this setup will be insecure unless sent over an SSL/TLS connection. Reconsider using SASL instead. You can use TIdSASLLogin to handle the old satDefault setup for servers that support AUTH LOGIN.

I am using gmail to send from. I get the following error:

EIdSocketError with Message 'Socket Error #11011' host not found

That could make sense if the user enters 'smtp.gmail.com' and you mangled it to 'SMTP.smtp.gmail.com', for instance.

After I get this working, I also need someone to tell me how to
modify it to send HTML.

See these articles:

http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.aspx

http://www.indyproject.org/Sockets/Blogs/RLebeau/20080116.aspx

I can generate the HTML message, but I need to know how to send it.

You send it the exact same way as any other email. The only difference
is in how you setup the TIdMessage's body content.

--
Remy Lebeau (TeamB)
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 30, 2017 3:48 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I have changed the code as follows:

procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
begin
  with idSMTP do
  begin
    Host := LowerCase( txtServer.text );
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    Port := Round( numPort.Value );
    if ( cbSSL.Checked ) then
      UseTLS := utUseExplicitTLS
    else
      UseTLS := utUseImplicitTLS;
    // 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 := 'smpt.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;


This gives me the error

Socket error #11001. Host not found

So I try to make 'smtp.verizon.net' the host and use port 25 with SSL unchecked
(and use appropriate password and To and From addresses switched). This
gives me the error

Could not load SSL library.

I know I'm doing something stupid, but this is my first venture into Indy.
I appreciate your patience and your help.

Thanks
Jim Sawyer


Remy Lebeau (TeamB) wrote:
Jim Sawyer wrote:
sHostStr := LowerCase( sHostStr );
if sHostStr = 'xtra.co.nz' then
Host := 'send.' + sHostStr
else
Host := 'SMTP.' + sHostStr;

Why are you doing any of that? The user should enter the hostname exactly as it is registered in DNS. Don't mess around with it. What if the user's SMTP server does not actually begin with 'smtp'? You would corrupt the hostname, which would easily explain the error you are getting. Just use the hostname as the user entered it, and let DNS handle the rest.

if ( txtServer.Text = 'smtp.gmail.com' ) then
begin
UseTLS := utUseExplicitTLS;
Port := 587;
end
else
begin
if ( sHostStr = 'xtra.co.nz' ) then
begin
UseTLS := utUseImplicitTLS;
Port := 465;
end
else
begin
UseTLS := utUseExplicitTLS;
Port := 25; // smpt usually runs on this port;
end;
end;

You shouldn't be doing any of that, either. Don't base your configuration on the hostname like that. There are thousands of SMTP servers in the world, and they support implicit or explicit TLS in their own ways, You are best off letting the user specify the desired port and TLS settings, don't assume them.

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

Note this setup will be insecure unless sent over an SSL/TLS connection. Reconsider using SASL instead. You can use TIdSASLLogin to handle the old satDefault setup for servers that support AUTH LOGIN.

I am using gmail to send from. I get the following error:

EIdSocketError with Message 'Socket Error #11011' host not found

That could make sense if the user enters 'smtp.gmail.com' and you mangled it to 'SMTP.smtp.gmail.com', for instance.

After I get this working, I also need someone to tell me how to
modify it to send HTML.

See these articles:

http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.aspx

http://www.indyproject.org/Sockets/Blogs/RLebeau/20080116.aspx

I can generate the HTML message, but I need to know how to send it.

You send it the exact same way as any other email. The only difference
is in how you setup the TIdMessage's body content.

--
Remy Lebeau (TeamB)
Alan Jeffery

Posts: 56
Registered: 2/10/00
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 30, 2017 6:49 PM   in response to: Jim Sawyer in response to: Jim Sawyer
Jim Sawyer wrote:
I have changed the code as follows:

Jim

You need two files ssleay32.dll and libeay32.dll. Those two files must be in the folder the executable is running from.

BTW - I see you seem to using some of the code we posted on here some years ago. Despite Remy's criticisms it does (DID?) work.

Now, for some reason it's "busted". Not on XP or Win 8. But it is on Win 7 and 10.

Please see my thread immediately below.

Alan


procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
begin
  with idSMTP do
  begin
    Host := LowerCase( txtServer.text );
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    Port := Round( numPort.Value );
    if ( cbSSL.Checked ) then
      UseTLS := utUseExplicitTLS
    else
      UseTLS := utUseImplicitTLS;
    // 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 := 'smpt.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;


This gives me the error

Socket error #11001. Host not found

So I try to make 'smtp.verizon.net' the host and use port 25 with SSL unchecked
(and use appropriate password and To and From addresses switched). This
gives me the error

Could not load SSL library.

I know I'm doing something stupid, but this is my first venture into Indy.
I appreciate your patience and your help.

Thanks
Jim Sawyer


Remy Lebeau (TeamB) wrote:
Jim Sawyer wrote:
sHostStr := LowerCase( sHostStr );
if sHostStr = 'xtra.co.nz' then
Host := 'send.' + sHostStr
else
Host := 'SMTP.' + sHostStr;

Why are you doing any of that? The user should enter the hostname exactly as it is registered in DNS. Don't mess around with it. What if the user's SMTP server does not actually begin with 'smtp'? You would corrupt the hostname, which would easily explain the error you are getting. Just use the hostname as the user entered it, and let DNS handle the rest.

if ( txtServer.Text = 'smtp.gmail.com' ) then
begin
UseTLS := utUseExplicitTLS;
Port := 587;
end
else
begin
if ( sHostStr = 'xtra.co.nz' ) then
begin
UseTLS := utUseImplicitTLS;
Port := 465;
end
else
begin
UseTLS := utUseExplicitTLS;
Port := 25; // smpt usually runs on this port;
end;
end;

You shouldn't be doing any of that, either. Don't base your configuration on the hostname like that. There are thousands of SMTP servers in the world, and they support implicit or explicit TLS in their own ways, You are best off letting the user specify the desired port and TLS settings, don't assume them.

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

Note this setup will be insecure unless sent over an SSL/TLS connection. Reconsider using SASL instead. You can use TIdSASLLogin to handle the old satDefault setup for servers that support AUTH LOGIN.

I am using gmail to send from. I get the following error:

EIdSocketError with Message 'Socket Error #11011' host not found

That could make sense if the user enters 'smtp.gmail.com' and you mangled it to 'SMTP.smtp.gmail.com', for instance.

After I get this working, I also need someone to tell me how to
modify it to send HTML.

See these articles:

http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.aspx

http://www.indyproject.org/Sockets/Blogs/RLebeau/20080116.aspx

I can generate the HTML message, but I need to know how to send it.

You send it the exact same way as any other email. The only difference
is in how you setup the TIdMessage's body content.

--
Remy Lebeau (TeamB)
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 1, 2017 6:54 AM   in response to: Alan Jeffery in response to: Alan Jeffery
I'm developing a 64 bit application. Will the two dll's referenced below, work with it?

Thanks,
Jim Sawyer

Alan Jeffery wrote:

Jim Sawyer wrote:
I have changed the code as follows:

Jim

You need two files ssleay32.dll and libeay32.dll. Those two files must be in the folder the executable is running from.

BTW - I see you seem to using some of the code we posted on here some years ago. Despite Remy's criticisms it does (DID?) work.

Now, for some reason it's "busted". Not on XP or Win 8. But it is on Win 7 and 10.

Please see my thread immediately below.

Alan


procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
begin
  with idSMTP do
  begin
    Host := LowerCase( txtServer.text );
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    Port := Round( numPort.Value );
    if ( cbSSL.Checked ) then
      UseTLS := utUseExplicitTLS
    else
      UseTLS := utUseImplicitTLS;
    // 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 := 'smpt.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;


This gives me the error

Socket error #11001. Host not found

So I try to make 'smtp.verizon.net' the host and use port 25 with SSL unchecked
(and use appropriate password and To and From addresses switched). This
gives me the error

Could not load SSL library.

I know I'm doing something stupid, but this is my first venture into Indy.
I appreciate your patience and your help.

Thanks
Jim Sawyer


Remy Lebeau (TeamB) wrote:
Jim Sawyer wrote:
sHostStr := LowerCase( sHostStr );
if sHostStr = 'xtra.co.nz' then
Host := 'send.' + sHostStr
else
Host := 'SMTP.' + sHostStr;

Why are you doing any of that? The user should enter the hostname exactly as it is registered in DNS. Don't mess around with it. What if the user's SMTP server does not actually begin with 'smtp'? You would corrupt the hostname, which would easily explain the error you are getting. Just use the hostname as the user entered it, and let DNS handle the rest.

if ( txtServer.Text = 'smtp.gmail.com' ) then
begin
UseTLS := utUseExplicitTLS;
Port := 587;
end
else
begin
if ( sHostStr = 'xtra.co.nz' ) then
begin
UseTLS := utUseImplicitTLS;
Port := 465;
end
else
begin
UseTLS := utUseExplicitTLS;
Port := 25; // smpt usually runs on this port;
end;
end;

You shouldn't be doing any of that, either. Don't base your configuration on the hostname like that. There are thousands of SMTP servers in the world, and they support implicit or explicit TLS in their own ways, You are best off letting the user specify the desired port and TLS settings, don't assume them.

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

Note this setup will be insecure unless sent over an SSL/TLS connection. Reconsider using SASL instead. You can use TIdSASLLogin to handle the old satDefault setup for servers that support AUTH LOGIN.

I am using gmail to send from. I get the following error:

EIdSocketError with Message 'Socket Error #11011' host not found

That could make sense if the user enters 'smtp.gmail.com' and you mangled it to 'SMTP.smtp.gmail.com', for instance.

After I get this working, I also need someone to tell me how to
modify it to send HTML.

See these articles:

http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.aspx

http://www.indyproject.org/Sockets/Blogs/RLebeau/20080116.aspx

I can generate the HTML message, but I need to know how to send it.

You send it the exact same way as any other email. The only difference
is in how you setup the TIdMessage's body content.

--
Remy Lebeau (TeamB)
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 1, 2017 7:23 AM   in response to: Jim Sawyer in response to: Jim Sawyer
I found 64 bit dll's and put them with my executable. Still won't work.
I'm running Windows 10.

Thanks,
Jim Sawyer

Jim Sawyer wrote:
I'm developing a 64 bit application. Will the two dll's referenced below, work with it?

Thanks,
Jim Sawyer

Alan Jeffery wrote:

Jim Sawyer wrote:
I have changed the code as follows:

Jim

You need two files ssleay32.dll and libeay32.dll. Those two files must be in the folder the executable is running from.

BTW - I see you seem to using some of the code we posted on here some years ago. Despite Remy's criticisms it does (DID?) work.

Now, for some reason it's "busted". Not on XP or Win 8. But it is on Win 7 and 10.

Please see my thread immediately below.

Alan


procedure TfrmTesting.btnSendEmailClick(Sender: TObject);
begin
  with idSMTP do
  begin
    Host := LowerCase( txtServer.text );
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    Port := Round( numPort.Value );
    if ( cbSSL.Checked ) then
      UseTLS := utUseExplicitTLS
    else
      UseTLS := utUseImplicitTLS;
    // 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 := 'smpt.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;


This gives me the error

Socket error #11001. Host not found

So I try to make 'smtp.verizon.net' the host and use port 25 with SSL unchecked
(and use appropriate password and To and From addresses switched). This
gives me the error

Could not load SSL library.

I know I'm doing something stupid, but this is my first venture into Indy.
I appreciate your patience and your help.

Thanks
Jim Sawyer


Remy Lebeau (TeamB) wrote:
Jim Sawyer wrote:
sHostStr := LowerCase( sHostStr );
if sHostStr = 'xtra.co.nz' then
Host := 'send.' + sHostStr
else
Host := 'SMTP.' + sHostStr;

Why are you doing any of that? The user should enter the hostname exactly as it is registered in DNS. Don't mess around with it. What if the user's SMTP server does not actually begin with 'smtp'? You would corrupt the hostname, which would easily explain the error you are getting. Just use the hostname as the user entered it, and let DNS handle the rest.

if ( txtServer.Text = 'smtp.gmail.com' ) then
begin
UseTLS := utUseExplicitTLS;
Port := 587;
end
else
begin
if ( sHostStr = 'xtra.co.nz' ) then
begin
UseTLS := utUseImplicitTLS;
Port := 465;
end
else
begin
UseTLS := utUseExplicitTLS;
Port := 25; // smpt usually runs on this port;
end;
end;

You shouldn't be doing any of that, either. Don't base your configuration on the hostname like that. There are thousands of SMTP servers in the world, and they support implicit or explicit TLS in their own ways, You are best off letting the user specify the desired port and TLS settings, don't assume them.

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

Note this setup will be insecure unless sent over an SSL/TLS connection. Reconsider using SASL instead. You can use TIdSASLLogin to handle the old satDefault setup for servers that support AUTH LOGIN.

I am using gmail to send from. I get the following error:

EIdSocketError with Message 'Socket Error #11011' host not found

That could make sense if the user enters 'smtp.gmail.com' and you mangled it to 'SMTP.smtp.gmail.com', for instance.

After I get this working, I also need someone to tell me how to
modify it to send HTML.

See these articles:

http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.aspx

http://www.indyproject.org/Sockets/Blogs/RLebeau/20080116.aspx

I can generate the HTML message, but I need to know how to send it.

You send it the exact same way as any other email. The only difference
is in how you setup the TIdMessage's body content.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 3, 2017 11:37 AM   in response to: Alan Jeffery in response to: Alan Jeffery
Alan Jeffery wrote:

You need two files ssleay32.dll and libeay32.dll. Those two files
must be in the folder the executable is running from.

Actually, they can be placed wherever you want them to be. If they are
not in the same folder as the EXE, and are not located in the system's
DLL search path, then you have to call Indy's IdOpenSSLSetLibPath()
function at program startup to specify where they are located.

--
Remy Lebeau (TeamB)
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: Email with Indy  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 1, 2017 3:09 PM   in response to: Jim Sawyer in response to: Jim Sawyer
Jim Sawyer wrote:

procedure TfrmTesting.FormActivate(Sender: TObject);
begin
txtServer.Text := 'smpt.gmail.com';

Are you REALLY sure about this? Looks wrong to me...

Simple testing with your data:

ping smpt.gmail.com
Ping request could not find host smpt.gmail.com. Please check the name
and try again.

Then with the correct hostname:

ping smtp.gmail.com

Pinging gmail-smtp-msa.l.google.com [64.233.161.108] with 32 bytes of
data:
Reply from 64.233.161.108: bytes=32 time=43ms TTL=45

--

Bo Berglund
Sweden & Texas
now using XanaNews 1.20-0cfde51
GPG public key: http://tinyurl.com/jbmuutu
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02