Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: How to send email rfom Embarcadero application


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


Permlink Replies: 5 - Last Post: Apr 24, 2018 1:07 PM Last Post By: Remy Lebeau (Te...
Garrett B

Posts: 77
Registered: 10/2/16
How to send email rfom Embarcadero application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2018 8:55 AM
Hi

I am using Embarcadero C++Builder XE with Indy 10.5.7.

I have surfed the net for examples of how to send an email from my application.
I have decided to try and send an email using my gmail account.

I am using the following Indy components:
TIdSMTP
TIdMessage
IdSSLIOHandlerSocketOpenSSL


Here is my code:
  /*
  // I commented out this code for now, as it does not change the exception error I get...

   IdSSLIOHandlerSocketOpenSSL1->MaxLineAction = maException;
   IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Method = sslvTLSv1;
   IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Mode = sslmUnassigned;
   IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyMode.Clear();
   IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyDepth = 0;
 */
 
   IdSMTP1->IOHandler = IdSSLIOHandlerSocketOpenSSL1;
   IdSMTP1->Port = 587;
   IdSMTP1->Host = "smtp.gmail.com";
   IdSMTP1->Username = my gmail address;
   IdSMTP1->Password = my password;
   IdSMTP1->UseTLS = utUseExplicitTLS;
   IdSMTP1->AuthType = satDefault;
   IdSMTP1->ValidateAuthLoginCapability = false;
 
   IdMessage1->Clear();
   IdMessage1->Recipients->EMailAddresses = another email address;
   IdMessage1->Subject = "email subject";
   IdMessage1->Body->Text = "email body";
   IdMessage1->From->Address = my gmail address;
 
   try {
      IdSMTP1->Connect();
      IdSMTP1->Send(IdMessage1);
   } catch (...) {
      ShowMessage("error....");
   }
   IdSMTP1->Disconnect();


Further research suggested that I needed to include the the following two dlls in my project - so I copied these to my project folder:
libeay32.dll
ssleay32.dll


After all this, when I run the application and click "Send", I get the following error:
Project myProject.exe raised exception class EIdOSSLCouldNotLoadSSLLibrary with message ‘Could not load SSL libray.’


I did find copies of the two dlls, and copied them into my application directory, but I don't know which versions of these dlls I require, or where I should get them.

Any help would be appreciated

Thanks

Garrett
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to send email rfom Embarcadero application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2018 1:31 PM   in response to: Garrett B in response to: Garrett B
Garrett B wrote:

I am using Embarcadero C++Builder XE with Indy 10.5.7.

The current version of Indy is 10.6.2(.5453), you really should
consider upgrading.

I am using the following Indy components:

TIdSMTP
TIdMessage
IdSSLIOHandlerSocketOpenSSL

That is the correct way to go.

IdSSLIOHandlerSocketOpenSSL1->MaxLineAction = maException;

You don't need to set that.

IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Mode = sslmUnassigned;

That should be set to sslmClient instead. It is OK to leave it as
sslmUnassigned, it will get flipped to sslmClient automatically while
connecting to the server.

IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyMode.Clear();

You can't clear a Set-based property like that. You are reading the
property into a temporary Set variable and then clearing the temporary
and not assigning it back to the property. You can clear the property
like this instead:

IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyMode =
TIdSSLVerifyModeSet();


However, you don't actually need this, since the VerifyMode is empty by
default.

IdSMTP1->Password = my password;

If you have 2-factor authentication enabled in your Google account, you
can't use your real Google password, unless you enable "less secure
apps" in your Google security settings. Otherwise, you have to
generate an application-specific password in your Google security
settings and use that password instead.

Further research suggested that I needed to include the the following
two dlls in my project - so I copied these to my project folder:
 libeay32.dll
ssleay32.dll

Corrrect.

After all this, when I run the application and click "Send", I get
the following error:
Project myProject.exe raised exception class
EIdOSSLCouldNotLoadSSLLibrary with message ‘Could not load SSL
libray.’

That means that either Indy could not load the OpenSSL DLLs into
memory, or Indy could not find 1 or more exported DLL functions that
Indy uses.

After the error occurs, you can call Indy's WhichFailedToLoad()
function (in IdSSLOpenSSLHeaders.hpp) to find out why Indy could not
load the OpenSSL DLLs.

Chances are, either you are using OpenSSL DLLs that have external
dependancies on other DLLs that you did not also deploy with your app,
such as the MSVC runtime (the OpenSSL DLLs at
http://indy.fulgan.com/SSL/ do not have external dependancies), or you
are simply using the wrong version of the OpenSSL DLLs to match your
version of Indy.

--
Remy Lebeau (TeamB)
Garrett B

Posts: 77
Registered: 10/2/16
Re: How to send email rfom Embarcadero application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 9:40 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you Remy.

I gave up trying to get it to work using my gmail account.
I don't have 2-factor authentication, but still couldn't get it working.
However, the overall goal of my work is to get something to working here at work, using the local server.

So first, I got things working with another email server (eastlink).
Here is the coed that works:
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Method = sslvTLSv1;
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Mode = sslmClient;
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyDepth = 0;
 
         IdSMTP1->IOHandler = IdSSLIOHandlerSocketOpenSSL1;
 
         IdSMTP1->Port = 587;
         IdSMTP1->Host = "mail.dccnet.com";
         IdSMTP1->Username = myemailaddress@dccnet.com;
         IdSMTP1->Password = mypassword;
         IdSMTP1->UseTLS = utUseExplicitTLS;
         IdSMTP1->AuthType = satDefault;
         IdSMTP1->ValidateAuthLoginCapability = false;
 
         IdMessage1->Clear();
         IdMessage1->Subject = "Subject here";
         IdMessage1->Body->Text = "Body here";
 
         IdMessage1->Recipients->EMailAddresses = myOtherEmailAddress;
         IdMessage1->From->Address = myemailaddress@dccnet.com;


So now, I am trying to change the above settings to get things working on the local server at work:
- I have been told to use Port 25, with no authentication, no encryption.
- Password is not required
- I keep getting the following error:
First chance exception at $767BC54F. Exception class EIdSMTPReplyError with message
'Client was not authenticated'.


Here is my code as it stands
I have tried changing various settings below but with no success:

         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Method = sslvTLSv1;
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Mode = sslmClient;
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
         IdSSLIOHandlerSocketOpenSSL1->SSLOptions->VerifyDepth = 0;
 
         IdSMTP1->IOHandler = IdSSLIOHandlerSocketOpenSSL1;
 
         IdSMTP1->Port = 25;
         IdSMTP1->Host = "xxx.xxx.xxx.xxx";
         IdSMTP1->Username = myUserName;
 
         IdSMTP1->UseTLS = utUseExplicitTLS;
         IdSMTP1->AuthType = satNone;
         IdSMTP1->ValidateAuthLoginCapability = false;
 
         IdMessage1->Clear();
         IdMessage1->Subject = "Subject here";
         IdMessage1->Body->Text = "Body here";
 
         IdMessage1->Recipients->EMailAddresses = myOtherEmailAddress;
         IdMessage1->From->Address = myWorkEmailAddress;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to send email rfom Embarcadero application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 23, 2018 2:36 PM   in response to: Garrett B in response to: Garrett B
Garrett B wrote:

I gave up trying to get it to work using my gmail account.

It works fine with Gmail, if you follow the instructions I outlined
earlier. I use it myself, so I can confirm it works.

So now, I am trying to change the above settings to get things working
on the local server at work: - I have been told to use Port 25, with
no authentication, no encryption. - Password is not required

- I keep getting the following error:

First chance exception at $767BC54F. Exception class
EIdSMTPReplyError with message 'Client was not authenticated'.

Then you were told wrong, or you misunderstood your requirements. The
server you are connecting to clearly requires authentication.

BTW, setting the TIdSMTP.UseTLS property to utUseExplicitTLS will
change the TIdSMTP.Port property to 587 if it is currently set to 25.
So, either set the TIdSMTP.Port back to 25 after setting
TIdSMTP.UseTLS, or just don't set TIdSMTP.UseTLS at all.

Since you were told not to use encryption, you really should not be
assigning an SSLIOHandler to the TIdSMTP.IOHandler property at all, and
you should not be setting the TIdSMTP.UseTLS property to anything other
than utNoTLSSupport.

In any case, none of this helps you fix your issue of not being able to
login to Gmail.

--
Remy Lebeau (TeamB)
Garrett B

Posts: 77
Registered: 10/2/16
Re: How to send email rfom Embarcadero application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 24, 2018 12:44 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy - thank you for your brilliant feedback and for your patience :)

()an> Remy Lebeau (TeamB) wrote:
Garrett B wrote:

I gave up trying to get it to work using my gmail account.

It works fine with Gmail, if you follow the instructions I outlined
earlier. I use it myself, so I can confirm it works.

Yes I got it working for my gmail.
I had to set up 2-factor authentication, and then set up a new password for apps.
Here is my code:
         SSL1->SSLOptions->Method = sslvSSLv23;
         SSL1->SSLOptions->Mode = sslmClient;
         SSL1->SSLOptions->VerifyMode = TIdSSLVerifyModeSet();
         SSL1->SSLOptions->VerifyDepth = 0;
 
         IdSMTP1->IOHandler = SSL1;
 
         IdSMTP1->Port = 465;
         IdSMTP1->Host = "smtp.gmail.com";
         IdSMTP1->Username = myGmailAddress@gail.com;
 
         IdSMTP1->Password = myGmailAppPassword;
         IdSMTP1->UseTLS = utUseExplicitTLS;
         IdSMTP1->AuthType = satDefault;
         IdSMTP1->ValidateAuthLoginCapability = false;
 
         IdMessage1->Clear();
         IdMessage1->Subject = "Subject here";
         IdMessage1->Body->Text = "Body here";
 
         IdMessage1->Recipients->EMailAddresses = myOtherEmailAddress;
         IdMessage1->From->Address = myGmailAddress@gail.com;



So now, I am trying to change the above settings to get things working
on the local server at work: - I have been told to use Port 25, with
no authentication, no encryption. - Password is not required

- I keep getting the following error:

First chance exception at $767BC54F. Exception class
EIdSMTPReplyError with message 'Client was not authenticated'.

Then you were told wrong, or you misunderstood your requirements. The
server you are connecting to clearly requires authentication.

I am still working on this - I have to wait until I have free time, and someone in the IT Dept has (same) free time - so I will post details back on this thread when it works.


BTW, setting the TIdSMTP.UseTLS property to utUseExplicitTLS will
change the TIdSMTP.Port property to 587 if it is currently set to 25.
So, either set the TIdSMTP.Port back to 25 after setting
TIdSMTP.UseTLS, or just don't set TIdSMTP.UseTLS at all.

Thank you for the info


Since you were told not to use encryption, you really should not be
assigning an SSLIOHandler to the TIdSMTP.IOHandler property at all, and
you should not be setting the TIdSMTP.UseTLS property to anything other
than utNoTLSSupport.

Yes you are right thanks

In any case, none of this helps you fix your issue of not being able to
login to Gmail.

Gmail now works :)


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


Posts: 9,447
Registered: 12/23/01
Re: How to send email rfom Embarcadero application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 24, 2018 1:07 PM   in response to: Garrett B in response to: Garrett B
Garrett B wrote:

IdSMTP1->Port = 465;
IdSMTP1->UseTLS = utUseExplicitTLS;

You need to use utUseImplicitTLS on port 465. Use utUseExplicitTLS on
ports 25 and 587 instead.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02