1

I tried to use this code to send email in an android app but I got this error

no apps can perform this action

code.java

private void send()
    {
        final String subject2 = subject.getText().toString().trim();
        final String message2 = message.getText().toString().trim();
        final String from2 = from.getText().toString().trim();
        String[] TO = {"recipientadress@gmail.com"};
        Uri uri = Uri.parse("mailto:"+from2)
                .buildUpon()
                .appendQueryParameter("subject", subject2)
                .appendQueryParameter("body", message2)
                .build();
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri);
        emailIntent.setType("text/plain");
        emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }

Can you help me please thanks in advance

Paolo.
  • 27
  • 4
  • If your current device does not have any app that can handle email, you can not use intents. – Joucks Jun 16 '16 at 11:04

1 Answers1

0

Using Intent android will try to look for an app to send the mail.

Alternatively, you can try javax-mail api to do that.

These links will be useful:

Adding a jar to Android Studio : Android Studio: Add jar as library?

Sending a mail using Javax mail http://www.tutorialspoint.com/java/java_sending_email.htm

Community
  • 1
  • 1
Anand Undavia
  • 3,493
  • 5
  • 19
  • 33
  • thanks I will check this link. I'm testing my app on genymotion. How can I install email apps. So every user should install email app before using my app. Is it impossible to send the email directly? – Paolo. Jun 16 '16 at 10:25
  • As such most of the android device has the email app. Just because you are using the virtual device, it doesn't have any email app. So if you use the intent to send the mail, then in the device, the email app will open and then user will have to send it manually. Using the java mail api, the mail will be sent without the user knowing it. "Is it impossible to send the email directly?" by directly, do you mean without user interaction ? In that case, it IS possible to send the email directly – Anand Undavia Jun 16 '16 at 11:02
  • So my code in my first post is correct? will it work correctly in a smartphone? because android can't anymore detect my smartphone. Have you an idea to detect it again? – Paolo. Jun 16 '16 at 21:59