[Android]Send email

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

[Android]Send email

Postby Lena » Thu Sep 29, 2016 2:58 am

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.
Lena
BCBJ Master
BCBJ Master
 
Posts: 407
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]Send email

Postby rlebeau » Thu Sep 29, 2016 5:36 pm

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).
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1371
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: [Android]Send email

Postby Lena » Fri Sep 30, 2016 1:41 am

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.
Lena
BCBJ Master
BCBJ Master
 
Posts: 407
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]Send email

Postby rlebeau » Fri Sep 30, 2016 3:04 pm

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);
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1371
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: [Android]Send email

Postby Lena » Sun Oct 02, 2016 3:33 am

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;
}
Lena
BCBJ Master
BCBJ Master
 
Posts: 407
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]Send email

Postby rlebeau » Mon Oct 03, 2016 12:47 pm

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.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1371
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: [Android]Send email

Postby Lena » Tue Oct 04, 2016 6:23 am

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.
Lena
BCBJ Master
BCBJ Master
 
Posts: 407
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]Send email

Postby rlebeau » Wed Oct 05, 2016 2:10 pm

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.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1371
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: [Android]Send email

Postby Lena » Sat Oct 08, 2016 12:36 am

Thank you!
Lena
BCBJ Master
BCBJ Master
 
Posts: 407
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests