Page 1 of 1

[Android]Send email

PostPosted: Thu Sep 29, 2016 2:58 am
by Lena
Hi.
How I can send email from tablet x86? I can’t use Indy because no found correct files libcrypto.so and libssl.so for x86.
Please show C++ example how use Intent for sends email.
Thanks.

Re: [Android]Send email

PostPosted: Thu Sep 29, 2016 5:36 pm
by rlebeau
Lena wrote:How I can send email from tablet x86?


There are two options:

1. use SMTP directly (which is what Indy does)

2. use an Intent to request Android invoke an email program on your behalf.

Lena wrote:I can’t use Indy because no found correct files libcrypto.so and libssl.so for x86.


Did you try the ones that are available at https://indy.fulgan.com/SSL/?

Lena wrote:Please show C++ example how use Intent for sends email.


See How send email Android with c++ builder? on StackOverflow for a couple of examples (there are other ways to use Intents to send emails).

Re: [Android]Send email

PostPosted: Fri Sep 30, 2016 1:41 am
by Lena
1. use SMTP directly (which is what Indy does)

I use AndroidOpenssl1.0.1t from https://indy.fulgan.com/SSL/
On the devices arm everything works fine. The emails was successfully sent with Indy.
On tablet GT-P5200 x86 my application works well but can't send emails. I got:
Failed to load /data/data/com.embarcadero.Mikros/files/libssl.so

See How send email Android with c++ builder? on StackOverflow

Thank you very much! I will try.
P.S.
Please could you explain how to add attachment file with Intent.

Re: [Android]Send email

PostPosted: Fri Sep 30, 2016 3:04 pm
by rlebeau
Lena wrote:I use AndroidOpenssl1.0.1t from https://indy.fulgan.com/SSL/
On the devices arm everything works fine. The emails was successfully sent with Indy.
On tablet GT-P5200 x86 my application works well but can't send emails. I got:
Failed to load /data/data/com.embarcadero.Mikros/files/libssl.so


Sorry, I don't have an answer for that. You will likely have to hunt down a 3rd party x86 version of the OpenSSL files.

Lena wrote:Please could you explain how to add attachment file with Intent.


You have to use the intent's EXTRA_STREAM field.

For a single attachment, you can do something like this:

Code: Select all
di_JFile AttachmentFile = TJFile::JavaClass->init(StringToJString(L"path to attachment file here"));
_di_Jnet_Uri Uri = TJnet_Uri::JavaClass->fromFile(AttachmentFile);
intent->putExtra(TJIntent::JavaClass->EXTRA_STREAM, TJParcelable::Wrap(((_di_ILocalObject)Uri)->GetObjectID()));


For multiple attachments, you can do something like this instead:

Code: Select all
_di_JArrayList Uris = new TJArrayList;

di_JFile AttachmentFile = TJFile::JavaClass->init(StringToJString(L"path to attachment file here"));
_di_Jnet_Uri Uri = TJnet_Uri::JavaClass->fromFile(AttachmentFile);
Uris->add(Uri);
// repeat for each attachment...

intent->putParcelableArrayListExtra(TJIntent::JavaClass->EXTRA_STREAM, Uris);

Re: [Android]Send email

PostPosted: Sun Oct 02, 2016 3:33 am
by Lena
Thank you!

I got error on my device:
android.content.ActivityNotFoundExcrption: No Activity found to handle Intent
{act=abdroid.intent.action.SendTO typ=message/rfc822 flg=0x10000000(has extras)}.


Where my mistake?
Code: Select all
#include <FMX.Helpers.Android.hpp>

void __fastcall TFormServis::Button3Click(TObject *Sender)
{
 Button3->Enabled = false;
 Application->ProcessMessages();

   _di_JIntent intent;
   //intent = new TJIntent; // <-- erorr no viable overloaded '='
   intent = TJIntent::JavaClass->init();
   intent->setAction(TJIntent::JavaClass->ACTION_SENDTO);
   intent->setData(StrToJURI(L"mailto:" + String("lenailicheva@yandex.ru")));
   // or: intent = TJIntent::JavaClass->init(TJIntent::JavaClass->ACTION_SENDTO, StrToJURI(L"mailto:" + address));
   intent->setFlags(TJIntent::JavaClass->FLAG_ACTIVITY_NEW_TASK);
   intent->putExtra(TJIntent::JavaClass->EXTRA_SUBJECT, StringToJString(L"Тест"));
   intent->setType(StringToJString(L"message/rfc822"));

   String path =
   System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"mikros.s3db");

   if(FileExists(path))
   {
    _di_JFile AttachmentFile = TJFile::JavaClass->init(StringToJString(path));
    _di_Jnet_Uri Uri = TJnet_Uri::JavaClass->fromFile(AttachmentFile);
    intent->putExtra(TJIntent::JavaClass->EXTRA_STREAM, TJParcelable::Wrap(((_di_ILocalObject)Uri)->GetObjectID()));
   }

   SharedActivity()->startActivity(intent);
   Button3->Enabled = true;
}

Re: [Android]Send email

PostPosted: Mon Oct 03, 2016 12:47 pm
by rlebeau
Lena wrote:I got error on my device:
android.content.ActivityNotFoundExcrption: No Activity found to handle Intent
{act=abdroid.intent.action.SendTO typ=message/rfc822 flg=0x10000000(has extras)}.



That error means you don't have an app installed that allows sending an email via a SENDTO intent.

Re: [Android]Send email

PostPosted: Tue Oct 04, 2016 6:23 am
by Lena
That error means you don't have an app installed that allows sending an email via a SENDTO intent.


Do You mean Project->Options->Uses Permitions?
What to add?
Thank you.

Re: [Android]Send email

PostPosted: Wed Oct 05, 2016 2:10 pm
by rlebeau
Lena wrote:Do You mean Project->Options->Uses Permitions?


No. I mean your code is sending an Intent object to Android with various criteria applied to it, and then Android checks the installed applications to see if any of them declare that they can accept an Intent with matching criteria. If a matching app is found, your Intent object gets passed to that app for handling, otherwise an error is reported.

The error you are seeing means Android could not find an app that can handle your Intent with action of SENDTO and type of "message/rfc822".

The code I gave you earlier is only *one* possible way to send an email via an Intent. There are other Intent values you can try. You should search around the Android forums for examples of sending emails via Intents, and then translate them to C++ as needed.

Re: [Android]Send email

PostPosted: Sat Oct 08, 2016 12:36 am
by Lena
Thank you!