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



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

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

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..."))

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

科特林:

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)
}
}

Java:

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);
}
}

相关内容

最新更新