首页 > 解决方案 > 我正在尝试在不打开选择器的情况下向多个人发送电子邮件,这可能吗?

问题描述

我正在尝试在不打开选择器的情况下向多个人发送电子邮件,这可能吗?

我尝试使用数组,但它给了我一个错误。

Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("example@gmail.com") +
        "?subject=" + Uri.encode("the subject") +
        "&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);
send.setData(uri);

startActivity(Intent.createChooser(send, "Send Email..."))

标签: javaandroidemailandroid-intent

解决方案


向多个用户发送电子邮件的正确方法是:

科特林:

private fun emailToMultipleUser() {
        val intent = Intent(Intent.ACTION_SEND)
        intent.type = "text/plain"
        intent.setPackage("com.google.android.gm")
        intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("example@gmail.com","chand@gmail.com"))
        intent.putExtra(Intent.EXTRA_SUBJECT, "email subject")
        intent.putExtra(Intent.EXTRA_TEXT, "Hi All ...")

        try {
            startActivity(Intent.createChooser(intent, "send mail"))
        } catch (ex: ActivityNotFoundException) {
            Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT)
        } catch (ex: Exception) {
            Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT)
        }

    }

爪哇:

private void  emailToMultipleUser() {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType( "text/plain");
        intent.setPackage("com.google.android.gm");
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"example@gmail.com","chand@gmail.com"});
        intent.putExtra(Intent.EXTRA_SUBJECT, "email subject");
        intent.putExtra(Intent.EXTRA_TEXT, "Hi All ...");

        try {
            startActivity(Intent.createChooser(intent, "send mail"));
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
        } catch (Exception ex) {
            Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
        }

    }

推荐阅读