1
votes

I am trying to send email using Indy 10.5.7 on C++ Builder XE but I get Host not found error. I added TIdSMTP, TIdSSLIOHandlerSocketOpenSSL and TIdMessage components. I set the host to smtp.office365.com, the port to 587 and UseTLS to utUseExplicitTLS. The username and password are set for the email address of the account I need to connect with.

I am trying to send the email using :

IdMessage1->From->Name = Name->Text;
IdMessage1->From->Address = EmailAddress->Text;
IdMessage1->Body = Msg->Lines;

try
{
    IdSMTP1->Connect(1000);
    try
    {
        IdSMTP1->Send(IdMessage1);
    }
    __finally
    {
        IdSMTP1->Disconnect();
    }
}
catch (const Exception &E)
{
    MessageBox(NULL, E.Message.c_str(), L"Error", MB_OK | MB_ICONERROR);
}
1
I tried to upgrade but I can't compile due to my c++ builder edition being starter. Can I use the pre-built versions on 'mjfreelancing.com/…' to upgrade Indy ?user6604390
I don't use a starter edition, what problems are you having with compiling? It does not appear that MJ's precompiled binaries are up-to-date, let alone support modern IDE editions in the past few years.Remy Lebeau
It says 'This version of the product does not support command line compiling'.user6604390
in that case, to update Indy, you will likely have to add Indy's source files directly to your project. Or, make your own C++Builder project files for Indy and compile it in the IDE. Indy stopped providing native C++Builder project files many years ago since the Delphi project files can be compiled on the command line for C++Builder. Indy does not account for the lack of command line compiling in the starter edition (in fact, I was not even aware of that restriction until just now).Remy Lebeau
I copied the source files into my project and compiled my project. I still receive the same error, do you know what could cause this, everything else can connect to the internet.user6604390

1 Answers

0
votes

This line is wrong:

IdSMTP1->Connect(1000);

In Indy 9, Connect() had an overload that accepted a timeout as input. But in Indy 10, that overload was removed, and the timeout parameter was reimplemented as a ConnectTimeout property.

Your original code compiles because Connect() in Indy 10 has an overload that takes a hostname String as input, overwriting the Host property, and (Ansi|Unicode)String has a constructor that accepts an int as input. Thus, your code is effectively doing this

IdSMTP1->Connect(String(1000));

Which tries to connect to a hostname named "1000", ignoring the "smtp.office365.com" hostname you assigned to the Host property. That is why you are getting socket error 11001.

You need to replace the offending line with this code instead:

//IdSMTP1->Connect(1000);
IdSMTP1->ConnectTimeout = 1000;
IdSMTP1->Connect();