Delphi XE2 - Indy 10 - SMTP server problem [Edit]

Dear folks

As  result of security issues one of the email services in NZ has changed the settings of their email server.  It used to be port 25 and outgoing mail was SMTP.xtra.co.nz.  The port is now 465 and outgoing mail is now send.xtra.co.nz.  The client configuration requires authentication and a secure connection (SSL).

The result is that my code to connect for everyone using that provider is now "busted".  I have changed the port and outgoing host accordingly.  And have set the IOHandler of idSMTP as IdSSLIOHandlerSocketOpenSSL1.  With the Authtype as satSASL.  I have also tried with satDefault.  The connection is not completed and there is a timeout.

There is a connection. In that there is no socket error.  But the message isn't sent.

Does anyone have any ideas?
{code}
            with idSMTP1 do
            begin
               sHostStr := LowerCase(sHostStr);
               if sHostStr = 'xtra.co.nz' then
                  Host := 'send.' + sHostStr
               else
                  Host := 'SMTP.' + sHostStr;
               if (sHostStr = 'gmail.com') then
               begin
                  IOHandler := IdSSLIOHandlerSocketOpenSSL1;
                  UseTLS := utUseExplicitTLS;
                  Port := 465;
               end else
               begin
                  if  (sHostStr = 'xtra.co.nz') then
                  begin
                     IOHandler := IdSSLIOHandlerSocketOpenSSL1;
                     AuthType := satSASL;
                     // UseTLS := utUseExplicitTLS;
                     // UseTLS := utNoTLSSupport;
                     Port := 465;
                  end else
                  begin
                     Port := 25; //smtp service usually runs on this port
                     UseTLS := utNoTLSSupport;
                  end;
               end;
               Password:= edPassword.Text;
            end;
            //setup idmessage parameters
            idmessage1.From.address:= edFrom.Text;
            idmessage1.Recipients.EMailAddresses:= edTo.Text;
            idmessage1.CCList.EMailAddresses:= edCC.Text;
            idmessage1.BccList.EMailAddresses:= edBC.Text;
            idmessage1.Subject := edSubject.Text;
            idmessage1.Body.Text := memo1.Lines.Text;
            //check if receipt confirmation is required
            if checkbox1.checked then
               //if required, set the sendback email address to your email address
               idmessage1.ReceiptRecipient.Text:= edfrom.Text;
            //send the message
            try
               btMsg.Enabled := False;
               idSMTP1.Connect;
               try
                  idSMTP1.send(idmessage1);
                  Result := True;
               //if an exception occurs…
               except
                  on E : EIdException do
                  begin
                     Showmessage('Connection failed.  You need to be online.' + E.Message);
                  end;
               end;
            finally
               //disconnect from server
               if IdSMTP1.Connected then
                  IdSMTP1.Disconnect;
               btMsg.Enabled := True;
            end;
{code}

Without any changes the exception returned a not online error.

Thanks

Alan

Edited by: Alan Jeffery on Oct 22, 2014 7:55 PM
0
Alan
10/23/2014 2:56:57 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

6 Replies
2115 Views

Similar Articles

[PageSpeed] 33

Alan wrote:

> As  result of security issues one of the email services in NZ has
> changed the settings of their email server.  It used to be port 25
> and outgoing mail was SMTP.xtra.co.nz.  The port is now 465 and
> outgoing mail is now send.xtra.co.nz.  The client configuration
> requires authentication and a secure connection (SSL).

On port 465, you usually need to set the UseTLS property to utUseImplicitTLS. 
 When sHostStr is 'xtra.co.nz', you are not setting UseTLS at all.

utUseImplicitTLS establishes a secure SSL session as soon as the socket is 
connected, before sending any SMTP-related messages.  This is typical usage 
for port 465.

utUseExplicitTLS establishes an unsecure socket connection, exchanges an 
SMTP hello greeting, and then sends an SMTP STARTTLS command to establish 
a secure SSL/TLS session only if the server supports STARTTTLS.  This is 
typical usage for port 597, but can be used on port 25 as well.

And SASL has nothing to do with SSL/TLS, though unsecure SASLs are typically 
not allowed over unsecure connections.

Try something more like this instead:

{code}
with idSMTP1 do
begin
  sHostStr := LowerCase(sHostStr);
  if sHostStr = 'xtra.co.nz' then
    Host := 'send.' + sHostStr
  else
    Host := 'SMTP.' + sHostStr;
  IOHandler := IdSSLIOHandlerSocketOpenSSL1;
  if (sHostStr = 'gmail.com') then
  begin
    // Gmail supports both implicit SSL and explicit TLS, so use whichever 
one you want...
    UseTLS := utUseImplicitTLS;
    Port := 465;
    {
    UseTLS := utUseExplicitTLS;
    Port := 587;
    }
  end
  else if (sHostStr = 'xtra.co.nz') then
  begin
    UseTLS := utUseImplicitTLS;
    Port := 465;
  end else
  begin
    UseTLS := utUseExplicitTLS; // just in case the server supports explicit 
TLS on port 25
    Port := 25;
  end;
  Password := edPassword.Text;
  AuthType := satSASL;
end;
{code}

--
Remy Lebeau (TeamB)
0
Remy
10/23/2014 4:47:29 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Alan wrote:
> 
> And SASL has nothing to do with SSL/TLS, though unsecure SASLs are typically 
> not allowed over unsecure connections.
> 
> Try something more like this instead:
> 
> {code}
> with idSMTP1 do
> begin
>   sHostStr := LowerCase(sHostStr);
>   if sHostStr = 'xtra.co.nz' then
>     Host := 'send.' + sHostStr
>   else
>     Host := 'SMTP.' + sHostStr;
>   IOHandler := IdSSLIOHandlerSocketOpenSSL1;
>   if (sHostStr = 'gmail.com') then
>   begin
>     // Gmail supports both implicit SSL and explicit TLS, so use whichever 
> one you want...
>     UseTLS := utUseImplicitTLS;
>     Port := 465;
>     {
>     UseTLS := utUseExplicitTLS;
>     Port := 587;
>     }
>   end
>   else if (sHostStr = 'xtra.co.nz') then
>   begin
>     UseTLS := utUseImplicitTLS;
>     Port := 465;
>   end else
>   begin
>     UseTLS := utUseExplicitTLS; // just in case the server supports explicit 
> TLS on port 25
>     Port := 25;
>   end;
>   Password := edPassword.Text;
>   AuthType := satSASL;
> end;
> {code}
> 
> --
Remy

Thanks for that. Progress. Of sorts.  I now get an exeption "Need SASL mechanism to login with".  Something missing?

Regards.

Alan

> Remy Lebeau (TeamB)
0
Alan
10/23/2014 9:07:16 PM
Alan wrote:

> Thanks for that. Progress. Of sorts.  I now get an exeption
> "Need SASL to login with".  Something missing?

You did not populate the TIdSMTP.SASLMechanisms collection with TIdSASL-derived 
components, but you were setting TIdSMP.AuthType to satSASL (all I did was 
move it so all Port configurations could use SASL).  Like I said, SASL and 
SSL/TLS are independant of each other.  SSL/TLS manages encryption of the 
socket communications, whereas SASL manages authentication with the SMTP 
server.  So either:

1. add some TIdSASL components into the TIdSMTP.SASLMechanisms and link them 
to a TIdUserPassProvider for UserName/Password.  CRAM-MD5 (TIdSASLCRAMMD5) 
and CRAM-SHA1 (TIdSASLCRAMSHA1) are popular, but you should also include 
LOGIN (TIdSASLLogin) as well.

2. set TIdSMTP.AuthType to satDefault and use TIdSMTP.Username and TIdSMTP.Password 
(and depending on your server's capabilities, you might need to set TIdSMTP.ValidateAuthLoginCapability 
to false as well).

--
Remy Lebeau (TeamB)
0
Remy
10/23/2014 10:26:07 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Alan wrote:
> 
> > Thanks for that. Progress. Of sorts.  I now get an exeption
> > "Need SASL to login with".  Something missing?
> 
> You did not populate the TIdSMTP.SASLMechanisms collection with TIdSASL-derived 
> components, but you were setting TIdSMP.AuthType to satSASL (all I did was 
> move it so all Port configurations could use SASL).  Like I said, SASL and 
> SSL/TLS are independant of each other.  SSL/TLS manages encryption of the 
> socket communications, whereas SASL manages authentication with the SMTP 
> server.  So either:
> 
> 1. add some TIdSASL components into the TIdSMTP.SASLMechanisms and link them 
> to a TIdUserPassProvider for UserName/Password.  CRAM-MD5 (TIdSASLCRAMMD5) 
> and CRAM-SHA1 (TIdSASLCRAMSHA1) are popular, but you should also include 
> LOGIN (TIdSASLLogin) as well.
> 
> 2. set TIdSMTP.AuthType to satDefault and use TIdSMTP.Username and TIdSMTP.Password 
> (and depending on your server's capabilities, you might need to set TIdSMTP.ValidateAuthLoginCapability 
> to false as well).
> 

Remy

Yes, I figured out how to add the SASL mechanisms to idSMTP.  I added the lot because of the need to connect to multiple ISPs.

However I can't see a means of connecting them to TIdUserPassProvider.

Nor do I know how to implement that.   I'll use idSMTP.Username - as that isn't being used so far.  Password is.

The code (as follows) works:

{code}
            with idSMTP1 do
            begin
               sHostStr := LowerCase(sHostStr);
               if sHostStr = 'xtra.co.nz' then
                  Host := 'send.' + sHostStr
               else
                  Host := 'SMTP.' + sHostStr;
               IOHandler := IdSSLIOHandlerSocketOpenSSL1;
               if (sHostStr = '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; //smtp service usually runs on this port
                  end;
               end;
               AuthType := satDefault;
               // AuthType := satSASL;
               Password:= edPassword.Text;
               UserName := edFrom.Text;
               ValidateAuthLoginCapability := False;
            end;
            //setup idmessage parameters
            idmessage1.From.address:= edFrom.Text;
            idmessage1.Recipients.EMailAddresses:= edTo.Text;
            idmessage1.CCList.EMailAddresses:= edCC.Text;
            idmessage1.BccList.EMailAddresses:= edBC.Text;
            idmessage1.Subject := edSubject.Text;
            idmessage1.Body.Text := memo1.Lines.Text;
            //check if receipt confirmation is required
            if Checkbox1.checked then
               //if required, set the sendback email address to email address
               idmessage1.ReceiptRecipient.Text:= edfrom.Text;
            //send the message
            try
               btMsg.Enabled := False;
               idSMTP1.Connect;
               try
                  // idSMTP1.Authenticate;
                  idSMTP1.send(idmessage1);
                  Result := True;
               //if an exception occurs…
               except
                  on E : EIdException do
                  begin
                     Showmessage('Connection failed.' + E.Message);
                  end;
               end;
            finally
               //disconnect from server
               if IdSMTP1.Connected then
                  IdSMTP1.Disconnect;
               btMsg.Enabled := True;
            end;
{code}

There is a an IdUserPassProvider on the form.  But the code doesn't call it.  Is it required?

Thanks

Alan
> --
> Remy Lebeau (TeamB)
0
Alan
10/23/2014 11:00:04 PM
Alan wrote:

> However I can't see a means of connecting them to TIdUserPassProvider.

Most of the TIdSASL components have a published UserPassProvider property 
that you can assign a TIdUserPassProvider component to.

> Nor do I know how to implement that.

Drop a TIdUserPassProvider component onto your Form (or create it in code) 
and assign it to the UserPassProvider property of the variable TIdSASL components.

> I'll use idSMTP.Username - as that isn't being used so far.  Password is.

That will only work with AuthType=satDefault, not with AuthType=satSASL. 
 satSASL requires TIdUserPassProvider.

> UserName := edFrom.Text;

You should not use the sender email as the username.  Create a separate input 
field for it.  On many SMTP systems, the sender email is not the same as 
the username.  Keep your authentication credentials separate from your email 
info.

> There is a an IdUserPassProvider on the form.

Sounds like you just need to link it to the TIdSASL components.

> But the code doesn't call it.  Is it required?

If you use AuthType=satSASL, yes.

--
Remy Lebeau (TeamB)
0
Remy
10/23/2014 11:51:34 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Alan wrote:
> 
> > However I can't see a means of connecting them to TIdUserPassProvider.
> 
> Most of the TIdSASL components have a published UserPassProvider property 
> that you can assign a TIdUserPassProvider component to.
> 
> > Nor do I know how to implement that.
> 
> Drop a TIdUserPassProvider component onto your Form (or create it in code) 
> and assign it to the UserPassProvider property of the variable TIdSASL components.
> 
> > I'll use idSMTP.Username - as that isn't being used so far.  Password is.
> 
> That will only work with AuthType=satDefault, not with AuthType=satSASL. 
>  satSASL requires TIdUserPassProvider.
> 
> > UserName := edFrom.Text;
> 
> You should not use the sender email as the username.  Create a separate input 
> field for it.  On many SMTP systems, the sender email is not the same as 
> the username.  Keep your authentication credentials separate from your email 
> info.
> 
> > There is a an IdUserPassProvider on the form.
> 
> Sounds like you just need to link it to the TIdSASL components.
> 
> > But the code doesn't call it.  Is it required?
> 
> If you use AuthType=satSASL, yes.
> 
> --

Remy

Thanks for that. Email connections reestablished.  I included all the SASL authentication types.  I have no idea which works for which ISP of course.

Regards.

Alan
> Remy Lebeau (TeamB)
0
Alan
11/9/2014 8:38:02 PM
Reply:

Similar Artilces:

Access to legacy (Delphi 4) Midas server from Delphi XE2 [Edit]
Hello, My company biggest product is developped with Delphi 4 and uses several Midas servers. It's a really big application (still in evolution, since 1997) , that has been started with Delphi 3. A partial or complete rewrite of this application is planned in a mid term future, and I must study if we can envisage a soft migration of some parts of the software on Delphi XE2 (or XE4), or if a complete rewrite even of the servers parts is required. If a complete rewrite must be done, my boss doesn't exclude to study the possibility of using another development environment to rewri...

converting delphi 2007 code to delphi XE2 -- emptyparam problem
Hi, I am trying to convert my applicantion code from delphi 2007 to delphi XE2 and i got stuck in this error "[DCC Error] ADODB_TLB.pas(4888): E2033 Types of actual and formal var parameters must be identical". This happens when we use emptyparam as an argument in a function that wants an olevariant. Example: function TAcadDatabase.CopyObjects(Objects: OleVariant): OleVariant; begin Result := DefaultInterface.CopyObjects(Objects, EmptyParam, EmptyParam); //this is where we get the ERROR end; The coyobjects function as this signature: " function CopyObjects(Object...

Delphi 2006 to Delphi XE Crystal BPL problem [Edit]
I am in the process of migrating our application from Delphi 2006 to Delphi XE and, for ease of use, I have both 2006 and XE installed on my development computer. I access Crystal Reports XI RDC in our application and so I rebuilt the BPL in XE in order to add the new package to XE. However, when I try to add the package to XE I get the error message: “Registration procedure, Craxddrt_tbl.Register in the package c:\Documents and Settings\All Uers\Documents\RADS Studio\8.0\BPL\Crystal.bpl raised exception class EFilerError: Component TDatabase can’t be registered by package crystal.bpl be...

TDatamodule problem on Delphi XE2 [Edit]
I reported a problem to QC (#100324) that I think is related with this issue. I've a project that I'm trying to compile with Delphi XE2 and when I close the application or close a form that links to the datamodule where my main connection to Interbase database is located, I'm geting this error message: First chance exception at $0061BCEA. Exception class $C0000005 with message 'access violation at 0x0061bcea: read of address 0x80808088'. Process Fac2011.exe (5608) For example, I have a form with a TIBTransaction and a TIBQuery that are linked to a TIBDatabase that b...

Access to legacy (Delphi 4) Midas server from Delphi XE2
Hello, My company biggest product is developped with Delphi 4 and uses several Midas servers. It's a really big application (still in evolution, since 1997) , that has been started with Delphi 3. A partial or complete rewrite of this application is planned in a mid term future, and I must study if we can envisage a soft migration of some parts of the software on Delphi XE2 (or XE4), or if a complete rewrite even of the servers parts is required. If a complete rewrite must be done, my boss doesn't exclude to study the possibility of using another development environment to rewri...

Delphi XE5 DataSnapRest server problem [Edit]
Hi all I use Delphi XE5, Update2. I made a small DataSnapRest Application. 1. If I select on step 3 "ServerModule" that is support for heavy callback, the web page does not working at all. (the default application that is created is not working when I press "Open Browser" button). 2. If I create a non "ServerModule" and the IDE put the TDSServer and TDSServerClass on the WebModule with the rest of the default components (like TDSHTTPWebDispatcher, TPageProducer, TDSProxyGenerator, TDSServerMetaDataProvider) is working well for a period of time. I cr...

Problem with printing, using Delphi XE2 [Edit]
I have problem with printing images using Delphi XE2. I have code Delphi 7, and this code work very well. {code} procedure Print; var ImgName: string; rect: TRect; jpg: TJPEGImage; begin OpenPictureDialog1.Execute; ImgName := OpenPictureDialog1.FileName; rect.TopLeft:=Point(0,0); rect.BottomRight:=Point(Printer.PageWidth,Printer.PageHeight); jpg := TJPEGImage.Create; jpg.LoadFromFile(ImgName); Printer.BeginDoc; Printer.Canvas.StretchDraw(rect,jpg); Printer.EndDoc; end; {code} But this code Delphi XE2 is not work, printer print clear sheets. (HP ...

Delphi 7 to Delphi XE2
Hi, Still using that old workhorse, Delphi7, but am going to the conference in London hosted by Embarcadero on Delphi XE2. Although I would like to "move with the times" and am keen to get the UNICODE and 64-bit support offered by the latest IDEs, I confess to being more than a little scared about all the UNICODE/String/AnsiString and 32/64 bit issues I'm probably going to fall over. Anyone recently upgraded from Delphi7 to one of the latest Delphi IDEs? Thanks, Alain On 03/02/2012 08:55, Alain Dekker wrote: > Still using that old workhorse, Delphi7, but...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Problem with Delphi XE2 using parameters in SQL query [Edit]
Hello, I have problem with using SQL with parameters. This part of code works fine on Delphi 2007, but have Debugger Exception Notification in Delphi XE2 with ADOTmp do *//works fine on Delphi2007 and Delphi XE2, date value is inserted* begin SQL.Clear; *SQL.Add('UPDATE Table SET Date = ''2012-04-03 13:13:13'' ');* ExecSQL; end; with ADOTmp do *//works fine on Delphi2007* begin SQL.Clear; *SQL.Add('UPDATE Table SET Date = :D1 ');* Parameters.ParamByName('D1').DataType := ftDateTime; Parame...

ANN: NexusDB 3.10 Starter Edition for Delphi XE2 available
Keeping in spirit with the recent Delphi XE2 release, NexusDB is happy to announce the immediate availability of the NexusDB Starter Edition for Delphi XE2, priced at a great Starter price: AUD 75. You can order your copy from: http://www.nexusdb.com/support/index.php?q=pricing The NexusDB Starter Edition is also available for Delphi XE. The NexusDB Starter Edition is a DCU/binary only edition that features full C/S capabilities with restricted SQL features. There are no artificial performance limitations or size restrictions. The NexusDB Starter Edition supports Delphi XE and X...

problem with Delphi XE2
Hello, I just install a new Delphi XE2 professionnal (without uninstall Delphi XE). I create a new classical VCL project and I try to compile it. I obtain this message : '[Error Erreur] Invalid PLATFORM variable "HPD". PLATFORM must be one of the following: "Win32", "Win64", or "OSX32". If PLATFORM is defined by your system's environment, it must be overridden in the RAD Studio IDE or passed explicitly on the command line to MSBuild; e.g., /p:Platform=Win32.' It seems that I have to indicate platform into the global options, not onl...

Problem with Delphi 6 to Delphi 7 upgrade
I have just purchased Delphi XE because I have an immediate need of D7 which came for free with XE. I downloaded and installed D7 and I think I applied the Update 1 that I had also downloaded. After much messing around with old components, I have finally attempted to compile my D6 project with D7. I get the following error:- [Fatal Error] apm.dpr(225): Unit ExtDlgs was compiled with a different version of ExtCtrls.TPanel I have checked the library paths all point to D7 versions of everything and now am at a loss to know what to do next. Also checked the sequence to make sure that al...

Convert Delphi 7 to Delphi 2009 [Edit]
Hi! Please, I have a code done in Delphi 7... Now I want to convert Delphi 7 to Delphi 2009 but I'm having problems when compile the code. Error message: +[DCC Fatal Error] Far.dpr(9): F2063 Could not compile used unit 'System.pas'+ Please can somebody help me? Source Download (349KB): http://rapidshare.com/files/256191328/FileManager.rar.html Mirror Source Download: http://www.megaupload.com/?d=12GYLPT0 Password: delphi Thank u so much! (sorry for my bad english, it is not my native language) Edited by: loquax loquax on Jul 15, 2009 12:24 PM Sorry, bu...

Is GNU Gettext for Delphi compatible with Delphi XE2 ?
The site http://dxgettext.po.dk declare support for Supports for Delphi 5-2009. Thanks in advance lior ilan wrote: > The site http://dxgettext.po.dk declare support for Supports for Delphi > 5-2009. > Thanks in advance It is, if you look in the forums mentioned in that website http://tech.groups.yahoo.com/group/dxgettext/ http://tech.groups.yahoo.com/group/dxgettext/message/3639 Regards Olivier ...

Web resources about - Delphi XE2 - Indy 10 - SMTP server problem [Edit] - embarcadero.delphi.winsock

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

The problem with using infrastructure to stimulate an economy
The immediate boost to the economy from infrastructure stimulus spending is minimal, while the cost for any new jobs it creates can be huge

The problem with “bringing the country together”
... our country needs is to reject the very premise of politics. The disparate factions in the United States don’t even agree on what our problems ...

Apple confirms bug that makes the iPhone’s most frustrating problem even more frustrating
... as and satisfied as they are though, we doubt any iPhone user would make the claim that his or her handset is perfect. No, iPhones have problems ...

A recurring problem in 'Making A Murderer' used to be huge in the UK — and the country figured out how ...
... Act of 1984 [PACE], however, subsequently required officers to videotape their interviews, among other provisions. It nearly solved the problem. ...

The problem with Chinese data...
John Rutledge, Safanad chief investment strategist, shares his thoughts on China's GDP and real economic growth. And Mike Santoli, CNBC senior ...

‘Degrassi: Next Class’: “The Drugs Have Changed But The Problems Are Still The Same”
Degrassi is known for tackling the complex issues that high school students face. Subjects such as teen pregnancy, drugs, school shooting and ...

Fujitsu wants to fix Japan's deer problem with software
Fujitsu is teaming up with a Japanese forest research institute to learn how animal populations grow. The pair will look into Sika deer, a creature ...

Free Basics, net neutrality, and the problem with charity
This must have been a pretty bad year for Mark Zuckerberg. He thought he'd be a hero, but now he's a pariah. Why?

We've Already Solved Oxfam's Little Inequality Problem
The World Economic Forum at Davos is fast approaching so Oxfam has decided to re-release their report screaming that we're all going to hell ...

Resources last updated: 1/19/2016 4:11:35 AM