Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Using Intent to send email - only offering email applications doesnt work

i am trying to create an intent activity that sends an email. Using

public void emailSend(View view){
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setData(Uri.parse("mailto:"));
        emailIntent.setType("plain/text");
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Nächstes Treffen");
        emailIntent.putExtra(Intent.EXTRA_EMAIL,adressListe);
        if (emailIntent.resolveActivity(getPackageManager()) != null){
            startActivity(emailIntent);
        }
    }

offers me more than just the email apps. Using

public void emailSend(View view){
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
        emailIntent.setData(Uri.parse("mailto:"));
        emailIntent.setType("plain/text");
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Nächstes Treffen");
        emailIntent.putExtra(Intent.EXTRA_EMAIL,adressListe);
        if (emailIntent.resolveActivity(getPackageManager()) != null){
            startActivity(emailIntent);
        }
    }

Nothing happens when i click the button. For

emailIntent.setType("plain/text");

is also tried

emailIntent.setType("messageage/rfc822");

and

emailIntent.setType("*/*");

all with varying results, but none only dislaying the email apps.

Do you have any idea how to solve this? Help would be greatly appreciated!

Thanks!

like image 962
JohnDoe Avatar asked Jan 01 '26 15:01

JohnDoe


2 Answers

When I use intent android.content.Intent.ACTION_SENDTO doesn't work for me because it shows many apps, some apps are not email clients. I found this way and it works perfectly for me.

Intent testIntent = new Intent(Intent.ACTION_VIEW);  
Uri data = Uri.parse("mailto:?subject=" + "text subject" + "&body=" + "text content" + "&to=" + "[email protected]");  
testIntent.setData(data);  
startActivity(testIntent);
like image 177
Geovanny Buitrago Avatar answered Jan 03 '26 07:01

Geovanny Buitrago


I see only email clients when using the next approach:

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String [] {[email protected]}); 
    emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Email subject"));
    Intent chooser = Intent.createChooser(emailIntent, "Mail to ..");
    if (emailIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(chooser);
    }
    else
       //Do something if there's no Email client
like image 25
iramm Avatar answered Jan 03 '26 07:01

iramm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!