当前位置: 动力学知识库 > 问答 > 编程问答 >

sending mail to multiple recipent from android application

问题描述:

Hi i am a newbie trying to send mails to multiple recipents from my android application but unsuccessfull.

Intent i = new Intent(android.content.Intent.ACTION_SEND);

i.setType("message/rfc822");

////i.setType("text/plain");

//get and prepare recp list

SharedPreferences sp = getSharedPreferences("filename", 0);

String v1 = sp.getString( "addr1","Incorrect Key");

String v2 = sp.getString( "addr2","Incorrect Key");

String v3 = sp.getString( "addr3","Incorrect Key");

String v4 = sp.getString( "addr4","Incorrect Key");

String s1 = v1.concat(",").concat(v2).concat(",").concat(v3).concat(",").concat(v4);

i.putExtra(Intent.EXTRA_EMAIL,new String[]{s1});

i.putExtra(Intent.EXTRA_SUBJECT, "On Sick Leave.");

i.putExtra(Intent.EXTRA_TEXT , "I am not feeling well so will be on Illness Leave today.");

i.putExtra(android.content.Intent.EXTRA_EMAIL,

new String[] { "[email protected]" });

try {

startActivity(Intent.createChooser(i, "Send mail..."));

} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(Insta_Msg.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();

}

}

it is not the issue with shared preference as i check in debugger i get all the 4 recipents mail ids correct .

when i click send mail goes to only 1 email id.

Thanks in advance ,

Vishesh.

网友答案:

You don't need to concatenate the e-mail addresses to a string, just build the String array with the available e-mail addresses

 i.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{v1,v2,v3,v4});
网友答案:

Try this

i.putExtra(Intent.EXTRA_EMAIL,new String[]{s1,s2,s3,s4});
// Here s1,s2,s3 and s4 are your mail IDs


Intent i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("message/rfc822");
        ////i.setType("text/plain");

        //get and prepare recp list
        SharedPreferences sp = getSharedPreferences("filename", 0);

        String v1 = sp.getString( "addr1","Incorrect Key");
        String v2 = sp.getString( "addr2","Incorrect Key");
        String v3 = sp.getString( "addr3","Incorrect Key");
        String v4 = sp.getString( "addr4","Incorrect Key");
        String s1 = v1.concat(",").concat(v2).concat(",").concat(v3).concat(",").concat(v4);            

        i.putExtra(Intent.EXTRA_EMAIL,new String[]{s1,s2,s3,s4});
        i.putExtra(Intent.EXTRA_SUBJECT, "On Sick Leave.");
        i.putExtra(Intent.EXTRA_TEXT   , "I am not feeling well so will be on Illness Leave today.");
        i.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] { "[email protected]" });
        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(Insta_Msg.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }


        }    
分享给朋友:
您可能感兴趣的文章:
随机阅读: