14

enter image description hereI am not able to pre fill the TO field in Email client to the "to" address mentioned in the extras here:

EmailImage.setOnClickListener(new OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                 // TODO Auto-generated method stub  
                Intent it = new Intent(Intent.ACTION_SEND_MULTIPLE);   
                it.putExtra(Intent.EXTRA_EMAIL, "toaddress@gmail.com");   
                it.putExtra(Intent.EXTRA_SUBJECT, "Regarding Policy Info");  
                it.putExtra(Intent.EXTRA_TEXT, "When is my next Premium due");  
                //it.setType("text/plain");   
                it.setType("message/rfc822");  
                startActivity(it);   
            }  
        });  

What is the problem?

Thanks
Sneha

Smitha
  • 6,110
  • 24
  • 90
  • 161
  • would you mind posting your working solution? (I'm facing the same issue, but I do have put the address in an array already...still empty "TO field") – vaiomike Feb 16 '12 at 21:13

5 Answers5

43

You need to put the address in an array:

it.putExtra(Intent.EXTRA_EMAIL, new String[] {"toaddress@gmail.com"});

See here.

MByD
  • 135,866
  • 28
  • 264
  • 277
  • what did it take to work now for you? (assuming that u provided a string array for recipient before?). maybe u can post the final working sample code!? thx. – vaiomike Feb 16 '12 at 14:32
  • @vaiomike Didn't understand the question. – MByD Feb 16 '12 at 14:33
  • My question was targeted @sneha, whether he could post his working solution. (I have the same problem, although I put the address in an array) – vaiomike Feb 16 '12 at 19:17
  • 1
    @vaiomike - so post the comment under his question, so he will be notified. – MByD Feb 16 '12 at 19:28
  • sry, my bad. thought he's notified since he has accepted this as the solution. – vaiomike Feb 16 '12 at 21:10
7

I've got something like this and its works:

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("plain/text");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.address" });
            intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
            intent.putExtra(Intent.EXTRA_TEXT, "mail body");
            startActivity(Intent.createChooser(intent, ""));
goodm
  • 7,275
  • 6
  • 31
  • 55
2

When using ACTION_SEND_MULTIPLE,

You have to provide an array of String for Intent.EXTRA_EMAIL Binyamin Sharet shown you.

If the requirement is to provide only one Address then use Intent.ACTION_SEND.

Vivek Khandelwal
  • 7,829
  • 3
  • 25
  • 40
0

This worked for me:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "someone@gmail.com" });
                        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, edt_msg.getText().toString());
                        emailIntent.putExtra(Intent.EXTRA_SUBJECT, edt_subjct.getText().toString());
                        emailIntent.setType("message/rfc822");

                        Uri uri = Uri.parse("file://" + file_img_capt);
                        emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                        startActivity(emailIntent);
0

Try this

Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"","your email"});
Ajay
  • 4,850
  • 2
  • 32
  • 44