1

I need to send an e-mail from my Android application. So, I send 2 parameters ( e-mail and subject) to the e-mail client app, but when app opens e-mail client, there is only subject parameter added, and email parameter is not set.

How I can fix this?

  String getMail = email.toString();
  Log.d("GET MAIL:",getMail);
  String subject = "Subject";
  Intent emailIntent = new Intent(Intent.ACTION_SEND);
  emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);
  emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

// need this to prompts email client only                                                
 emailIntent.setType("message/rfc822");
 startActivity(Intent.createChooser(emailIntent,"Choose E-mail client:"));
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Zookey
  • 2,637
  • 13
  • 46
  • 80

3 Answers3

3
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

                   emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"me@gmail.com"}); 
                   emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
                   emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From App"); 

                   startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39
2

Change emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);

to:

emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{getMail});
Mohit Verma
  • 3,025
  • 1
  • 20
  • 36
2

getMail should be a string array...

anz
  • 1,317
  • 2
  • 13
  • 25