Indy and Android

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Re: Indy and Android

Postby rlebeau » Wed Jun 01, 2016 4:08 pm

Lena wrote:However, I got a strange error :(


The error message is pretty self-explanatory. Your Android device could not resolve the hostname "smtp.yandex.ru" to an IP address for TIdSMTP to connect to (on my Windows machine, that hostname resolves to 93.158.134.38). Error code 7 is EAI_NONAME ("The node or service is not known"). That is a networking DNS issue, not an Indy issue. Is your device connected to the Internet using a WiFi or cellular connection? Does your app have the INTERNET permission enabled in its Android manifest?
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1395
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Indy and Android

Postby Lena » Wed Jun 01, 2016 10:08 pm

I think it is a problem of mail service yandex.ru
Today I got a new error (see att.).
I try to change to another Russian mail service.

Code: Select all
TIdEMailAddressItem *Item = IdMessage1->Recipients->Add();
Item->Domain = L"yandex.ru";
Item->User = L"tracklogic"; //toughest test
Attachments
1.jpg
1.jpg (39.57 KiB) Viewed 5055 times
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby Lena » Wed Jun 01, 2016 10:42 pm

I try new mail servis:
IdMessage1->Clear();
IdMessage1->Subject = L"База данных 1"; //<- test

TIdEMailAddressItem *Item = IdMessage1->Recipients->Add();
//Item->User = Edit3->Text;
//Item->Domain = L"yandex.ru";
Item->User = L"shelkinohouse";
Item->Domain = L"mail.ru";

std::unique_ptr<TIdMessageBuilderPlain> builder(new TIdMessageBuilderPlain);
****


And I got the same error not owned by aut user :(
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby Lena » Wed Jun 01, 2016 11:07 pm

I went back to my old wrong code, and all errors are gone :shock:
Code: Select all
   Button3->Enabled = false;
    try
     {
      try
        {
       IdMessage1->Body->Text = L"От: " + Edit2->Text;
       IdMessage1->Subject = L"База данных 1";

       TIdEMailAddressItem *Item = IdMessage1->Recipients->Add();
       Item->User = Edit3->Text;
       Item->Domain = L"yandex.ru";

       #if defined(_PLAT_IOS) || defined(_PLAT_ANDROID)
         String att = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath
         (), "mikros.s3db");
       #endif

       std::unique_ptr<TIdAttachmentFile> attachment(new TIdAttachmentFile(IdMessage1->MessageParts, att));


         IdSMTP1->Connect();
         try
          {
              IdSMTP1->Send(IdMessage1);
          }
              __finally
              {
            IdSMTP1->Disconnect();
              }


         _di_TInputCloseDialogProc handler = new TCloseDialogHandler();
         String MES = (L"Письмо отправлено.");
       MessageDlg(MES, TMsgDlgType::mtInformation,   TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0, handler);

          }
        catch (EIdException &E)
         {

          _di_TInputCloseDialogProc handler = new TCloseDialogHandler();
             String MES = (L"Ошибка. " + E.Message);
             MessageDlg(MES, TMsgDlgType::mtInformation,   TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0, handler);

         }

    }
      __finally
           {
       Button3->Enabled = true;
       }




Code: Select all
void __fastcall TFormServis::IdMessage1InitializeISO(System::WideChar &VHeaderEncoding,
        UnicodeString &VCharSet)
{
   VCharSet = L"UTF-8";
   VHeaderEncoding = L'B';
}


Received: from smtp13.mail.yandex.net ([95.108.130.68])
by mxback9g.mail.yandex.net with LMTP id lMST1xgX
for <tracklogic@yandex.ru>; Thu, 2 Jun 2016 09:55:15 +0300
Received: from smtp13.mail.yandex.net (localhost [127.0.0.1])
by smtp13.mail.yandex.net (Yandex) with ESMTP id 698D8E40AF5
for <tracklogic@yandex.ru>; Thu, 2 Jun 2016 09:55:15 +0300 (MSK)
Received: by smtp13.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id szEIqsZlzI-tEuWjdhK;
Thu, 02 Jun 2016 09:55:14 +0300
(using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits))
(Client certificate not present)
X-Yandex-Front: smtp13.mail.yandex.net
X-Yandex-TimeMark: 1464850514
Message-Id: <20160602095514.tEuWjdhK@smtp13.mail.yandex.net>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1464850514;
bh=zoxTCRjE/hZA+wkPq1pLW9/sC0Hmnul+dVqX2KuHDGU=;
h=From:Subject:To:Content-Type:MIME-Version:Date;
b=kmvMaFc/W+jOKLt8nFV9H3vBxnXOiWZLzoJGYlVYY4cdYQYUlXUnwy/llCoYxTQkn
mArk3l21pMO9nuOWYMg2iPtKo8LEfpFFPhn6HEx6bHYYqiLhSUMTTVFuDF4lv/wbTk
UsvMR4J5pvrFxkk0BaCI70qIz4w7tv9V9+bGlhQc=
Authentication-Results: smtp13.mail.yandex.net; dkim=pass header.i=@yandex.ru
X-Yandex-Spam: 1
From: "vlad44b@yandex.ru" <vlad44b@yandex.ru>
Subject: =?UTF-8?B?0JHQsNC30LAg0LTQsNC90L3Ri9GF?= 1
To: tracklogic@yandex.ru
Content-Type: text/plain; charset=windows-1251; boundary="8fVHA1kJ7tmsgLS6On6e8BXSfg9fKo6=_m"
MIME-Version: 1.0
Date: Thu, 2 Jun 2016 09:55:13 +0300
Return-Path: vlad44b@yandex.ru
X-Yandex-Forward: 2afb61b9a326cc07122fee686c7054b1

This is a multi-part message in MIME format

--8fVHA1kJ7tmsgLS6On6e8BXSfg9fKo6=_m
Content-Type: text/plain; charset="windows-1251"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=CE=F2: =CA=F3=E7=FF

--8fVHA1kJ7tmsgLS6On6e8BXSfg9fKo6=_m
Content-Type: application/octet-stream;
name="mikros.s3db"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="mikros.s3db"

U1FMaXRlIGZvcm1hdCAzAAQAAQEAQCAgAAAA7AAAAAkAAAAAAAAAAAAAACYAAAABAAAAAAAAAAAA
AAABAAAAAAAAAAA...
Last edited by Lena on Thu Jun 02, 2016 12:00 am, edited 1 time in total.
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby Lena » Thu Jun 02, 2016 5:44 am

I got ! I think I found a bug in the С++ Builder 10.1
It is necessary to somehow duplicate the code from the Object Inspector!
Showing a picture with my settings, but this is not enough.
It is necessary to duplicate code
Code: Select all
Button3->Enabled = false;
try
  {
      try
      {
        IdMessage1->Clear();
        IdMessage1->Subject = L"База данных 1";
//It is necessary to somehow duplicate the code from the Object Inspector!
        IdMessage1->From->Address = L"vlad44b@yandex.ru";
        IdMessage1->From->Domain = L"yandex.ru";
        IdMessage1->From->Text = L"vlad44b@yandex.ru";
        IdMessage1->From->User = L"vlad44b";

        TIdEMailAddressItem *Item = IdMessage1->Recipients->Add();
        Item->User = Edit3->Text;
        Item->Domain = L"yandex.ru";

        std::unique_ptr<TIdMessageBuilderPlain> builder(new TIdMessageBuilderPlain);

        builder->PlainText->Text = L"От: " + Edit2->Text;
        builder->PlainTextCharSet = L"utf-8";
        builder->PlainTextContentTransfer = L"binary";

        #if defined(_PLAT_IOS) || defined(_PLAT_ANDROID)
        String att = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"mikros.s3db");
        builder->Attachments->Add(att);
          #endif

        builder->FillMessage(IdMessage1);

        IdSMTP1->Connect();
        try {
          IdSMTP1->Send(IdMessage1);
        }
        __finally {
          IdSMTP1->Disconnect();
        }

        _di_TInputCloseDialogProc handler = new TCloseDialogHandler();
        String MES = L"Письмо отправлено.";
        MessageDlg(MES, TMsgDlgType::mtInformation,   TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0, handler);
      }
      catch (const Exception &E)
        {
         _di_TInputCloseDialogProc handler = new TCloseDialogHandler();
         String MES = L"Ошибка отправки. " + E.Message;
         MessageDlg(MES, TMsgDlgType::mtInformation,   TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0, handler);
         }
  }
  __finally
   {
    Button3->Enabled = true;
   }




I received the correct email. No error: not owned by aut user.
Thank you very much!
Attachments
1.jpg
1.jpg (35.47 KiB) Viewed 5050 times
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby rlebeau » Thu Jun 02, 2016 4:53 pm

Lena wrote:I got ! I think I found a bug in the С++ Builder 10.1


No, you did not find a bug.

Lena wrote:It is necessary to somehow duplicate the code from the Object Inspector!


The code I gave you Clear()'ed the TIdMessage, so of course you would have to re-assign various properties after that, especially TIdMessage::From. If you don't want to do that every time you Send() a TIdMessage, then replace TIdMessage::Clear() with TIdMessage::ClearBody() instead so the properties are preserved. Just be sure to Clear() the Recipients, at least. Or, stop using the Recipients->Add() method and instead use the Recipients->EmailAddresses property.

Code: Select all
IdMessage1->Recipients->EmailAddresses = Edit3->Text + L"@yandex.ru";


Lena wrote:
Code: Select all
IdMessage1->From->Address = L"vlad44b@yandex.ru";
IdMessage1->From->Domain = L"yandex.ru";
IdMessage1->From->Text = L"vlad44b@yandex.ru";
IdMessage1->From->User = L"vlad44b";



As I told you earlier, you DO NOT need to use the Address and Text properties if you use the User and Domain properties instead, and vice versa.

Code: Select all
IdMessage1->From->Address = L"vlad44b@yandex.ru";


Or:

Code: Select all
IdMessage1->From->Text = L"vlad44b@yandex.ru";


Or:

Code: Select all
IdMessage1->From->User = L"vlad44b";
IdMessage1->From->Domain = L"yandex.ru";
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1395
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Indy and Android

Postby Lena » Fri Jun 03, 2016 3:34 am

Thank you very much for the detailed explanation! Now everything is clear. :)
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby Lena » Wed Aug 10, 2016 1:07 am

I installed my apk on several devices (phones and two tablets with android 4.4.2).
When I send Indy emails to all this devices all right. However, on one tablet I got can not load the SSL library.
This occurs only on one tablet Sumsung PG 5200 (no root). How can I fix this tablet?
All good on other devices.
Attachments
pic1.jpg
pic1.jpg (149.04 KiB) Viewed 4530 times
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby rlebeau » Wed Aug 10, 2016 7:48 pm

Lena wrote:However, on one tablet I got can not load the SSL library.


That could be happening for any number of reasons. You have not provided enough information to diagnose the problem. For instance, what does Indy's WhichFailedtoLoad() function (declared in IdSSLOpenSSLHeaders.hpp) report after the error happens?

Lena wrote:This occurs only on one tablet Sumsung PG 5200 (no root).


There is no Samsung PG 5200. Do you mean the P5200 (Galaxy Tab 3)? Are you sure the tablet is actually running Android 4.4.2 and hasn't been updated to Android 6?
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1395
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Indy and Android

Postby Lena » Thu Aug 11, 2016 5:16 am

Thank you for your help.

In my tablet Pipo M7 Pro I have full access to all files on the device because I have root access.
After install apk I go in folder /data/data/com.embarcadero.Mikros/files/ and I see
libcrypto.so
libssl.so
mikros.s3db
On this tablet all work fine.

For tablet users Samsung GT-P5200 Android 4.4.2 have no root rights.
I do not see the folder /data/data/ is hidden.
After install apk and try send email I got error in ini file:
[ERROR]
error="Failed to load /data/data/com.embarcadero.Mikros/files/libssl.so."

But database file mikros.s3db loaded correctly. I can insert records into the database in my application on this tablet. I have error only when try send email on this tablet.

What is your advice for this situation?

Code: Select all
try
      {
//other code***********************


        builder->FillMessage(IdMessage1);

        IdSMTP1->Connect();
        try {
          IdSMTP1->Send(IdMessage1);
        }
        __finally {
          IdSMTP1->Disconnect();
        }

        ShowMessage(L"Send.");
      }
      catch (const EIdOSSLCouldNotLoadSSLLibrary &)
       {
         String ErMessage = WhichFailedToLoad();
         String path = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetSharedDownloadsPath(), L"error.ini");
         if(FileExists(path))
          {
                          std::unique_ptr<TIniFile> FileINI(new TIniFile(path));
           FileINI->WriteString(L"ERROR",L"error",ErMessage);
                          ShowMessage(L"Write in error.ini");
                         }
            else
            {
             ShowMessage(L"No error.ini");
                           }

      }
          catch (const Exception &E)
        {
                   String MES = L"Other error. " + E.Message;
         ShowMessage(MES);
        }
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby rlebeau » Thu Aug 11, 2016 7:38 pm

Lena wrote:For tablet users Samsung GT-P5200 Android 4.4.2 have no root rights.
I do not see the folder /data/data/ is hidden.
After install apk and try send email I got error in ini file:
[ERROR]
error="Failed to load /data/data/com.embarcadero.Mikros/files/libssl.so."


It is pretty hard to diagnose if you can't even verify whether the .so files are being deployed into that folder correctly.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1395
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Indy and Android

Postby Lena » Thu Aug 11, 2016 10:44 pm

May be I put this code in wrong place?
IdOpenSSLSetLibPath(System::Ioutils::TPath::GetDocumentsPath());

This code in main cpp:
#include <System.StartupCopy.hpp>
#include <IdSSLOpenSSLHeaders.hpp>

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
IdOpenSSLSetLibPath(System::Ioutils::TPath::GetDocumentsPath());
}

P.S.
The tablet not in my hands. I'll try this new code. Then I go to the user and will update apk:
Code: Select all
 __fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
String libcrypto = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"libcrypto.so");
String libssl = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"libssl.so");

   if(FileExists(libcrypto) && FileExists(libssl))
     {
      IdOpenSSLSetLibPath(System::Ioutils::TPath::GetDocumentsPath());
     }
    else
       {
        //manualy copy libcrypto.so and libssl.so in public folder android Download
        IdOpenSSLSetLibPath(System::Ioutils::TPath::GetSharedDownloadsPath());
       }
}

Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby rlebeau » Sat Aug 13, 2016 11:43 pm

Lena wrote:May be I put this code in wrong place?
IdOpenSSLSetLibPath(System::Ioutils::TPath::GetDocumentsPath());


You can put it wherever you want, as long as it is called before Indy needs to use OpenSSL. The error message you showed proves that the path you specify was assigned correctly. The problem has to be with the .so files themselves. Either the files are not being deployed to the folder, or the files are corrupted, or otherwise are not loading correctly.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1395
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Indy and Android

Postby Lena » Mon Aug 15, 2016 4:09 am

My new steps:
1. Remove files libcrypto.so and libssl.so from Deployment manager.
2. Manually copy both files on the both tablets to android devices folder Download - libcrypto.so and libssl.so.
3. Change code for android folder Download:
IdOpenSSLSetLibPath(System::Ioutils::TPath::GetSharedDownloadsPath());
4. Install APK to tablets PIPO M7 pro and Samsung GT-P5200.
5. Send Indy email from application.

In PIPO M7 pro everything works as expected.

In Samsung GT-P5200 got error:
[ERROR]
error="Failed to load /storage/emulated/0/Download/libssl.so."

I cannot understand why this tablet cannot load the file libssl.so :(
What else to try?
Thank you.
Lena
BCBJ Master
BCBJ Master
 
Posts: 450
Joined: Sun Feb 06, 2011 1:28 pm

Re: Indy and Android

Postby rlebeau » Mon Aug 15, 2016 3:32 pm

Lena wrote:I cannot understand why this tablet cannot load the file libssl.so :(


My guess, and this is just a guess, is that the .so file itself is probably not compatible with that tablet and/or OS version. Or maybe it is linked to a dependent .so file that it cannot find.

Lena wrote:What else to try?


I don't know. This is WAY outside my area of expertise. My experience with Android is VERY limited, and my experience with Linux (which Android runs on top of) is non-existent.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1395
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

PreviousNext

Return to Technical

Who is online

Users browsing this forum: No registered users and 7 guests

cron