从Android应用程序向多个收件人发送邮件

时间:2013-12-04 13:48:42

标签: android

嗨,我是一个新手试图从我的Android应用程序发送邮件到多个配方但不成功。

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[] { "vishesh.ab@gmail.com" });
        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();
        }


        }        

这不是共享偏好的问题,因为我在调试器中检查我得到所有4个配方邮件ID正确。

当我点击发送邮件时,只有1个电子邮件ID。

提前致谢, Vishesh。

2 个答案:

答案 0 :(得分:0)

您不需要将电子邮件地址连接到字符串,只需使用可用的电子邮件地址构建String数组

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

答案 1 :(得分:0)

试试这个

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[] { "vishesh.ab@gmail.com" });
        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();
        }


        }