Send Email to Multiple Addresses Android

限于喜欢 提交于 2019-12-03 13:31:56

问题


I want to select a number of email addresses and then send an email to all of them.

My code is as below:

emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{listofemailaddresses});
emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "My Subject");
emailIntent .putExtra(android.content.Intent.EXTRA_TEXT, Constants.SMS_MESSAGE);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));`

listofemailaddresses is a string which contains all the emails separated by a ',' sign. But the To field is always empty in this.


回答1:


Add this line to your code:

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
            new String[] { "appsupport@YOUR_DOMAIN.com" });

This will fill the "To" section of your screen.




回答2:


If you having the list of email addresses seprated by , then split that string to get individual email id as follow:
String [] emailList = emailAddresses.split(",");
now use emailList with your Intent.EXTRA_EMAIL key,as this will show all email addresses inside to field of send email form.

How about this code:

final Intent emailLauncher = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailLauncher.setType("message/rfc822");
emailLauncher.putExtra(Intent.EXTRA_EMAIL, emailList);
emailLauncher.putExtra(Intent.EXTRA_SUBJECT, "check this subject line");
emailLauncher.putExtra(Intent.EXTRA_TEXT, "hey check this message body!");
try{
       startActivity(emailLauncher);
}catch(ActivityNotFoundException e){

}



回答3:


Intent intent = null;
intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL,new String[] { "abc@gmail.com" , "test@gmail.com", "xyz@test.com"});
startActivity(intent);


来源:https://stackoverflow.com/questions/9716924/send-email-to-multiple-addresses-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!