如何将电子邮件发送到多个recepients android系统中?多个、发送到、如何将、电子邮件

2023-09-06 06:24:08 作者:初遇未遇

我在Android的一个新手。请帮我。我不能发送电子邮件给多个收件人。 这是我的code。

 公共类SendEmailActivity延伸活动{

的EditText subject_ed,message_ed;
TextView的subject_tv,message_tv;
按钮send_btn;

 ArrayList的<字符串>的emailList;
 ArrayList的<整数GT; IDLIST;
 INT事件ID;
@覆盖
保护无效的onCreate(包savedInstanceState){
    // TODO自动生成方法存根
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.contacts_email_sms_layout);
    setupViews();
    意向意图= getIntent();
    叠B = intent.getExtras();
    事件ID = b.getInt(事件ID); //事件ID
    IDLIST = b.getIntegerArrayList(IDLIST); // ID列表
    的emailList = b.getStringArrayList(的emailList); //电子邮件ID列表
    buttonListeners();
}

公共无效setupViews()
{
    subject_ed =(EditText上)findViewById(R.id.ed_subject_email);
    message_ed =(EditText上)findViewById(R.id.ed_msg_body);
    subject_tv =(TextView中)findViewById(R.id.tv_subject_email);
    message_tv =(TextView中)findViewById(R.id.tv_msg_body);
    send_btn =(按钮)findViewById(R.id.btn_send_sms_email);
}

公共无效buttonListeners()
{
    send_btn.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            Toast.makeText(getApplicationContext(),通过电子邮件发送,Toast.LENGTH_LONG).show();
            //字符串= textTo.getText()的toString();
              字符串主题= subject_ed.getText()的toString()。
              字符串消息= message_ed.getText()的toString()。
            [对象]为= emailList.toArray();
//的for(int i = 0; I< = emailList.size();我++)
//// {
////
//字符串= emailList.get(0);
////
////}



              意图电子邮件=新的意图(Intent.ACTION_SEND);
              的for(int i = 0; I< to.length;我++)
                {
                    Log.i(字符串,(串)[I]);
                    //的String []海峡=(字符串[])在[I];
                     email.putExtra(Intent.EXTRA_EMAIL,+(串)[我] +');
                }

              email.putExtra(Intent.EXTRA_SUBJECT,学科);
              email.putExtra(Intent.EXTRA_TEXT,消息);

              //需要这样的提示只是电子邮件客户端
              email.setType(信息/ RFC822);

              startActivity(Intent.createChooser(电子邮件,选择电子邮件客户端));
             // 完();
        }
    });
}

}
 

解决方案

首先,你需要做如下从你的列表转换为字符串[]是错误的。

 名单,其中,字符串>名单=新的ArrayList<字符串>();
的String [] arrayOfStrings = list.toArray(新的String [则为list.size());
 

和接下来的事情就是,你需要一提的android.Content.Intent,如下:

所以,最后你需要改变如下:

 的ArrayList<字符串>的emailList;
的emailList = b.getStringArrayList(的emailList);
的String [] emailArray;
意图电子邮件=新的意图(android.content.Intent.ACTION_SEND);
的for(int i = 0; I< to.length;我++){
Log.i(字符串,(串)[I]);
email.putExtra(android.content.Intent.EXTRA_EMAIL,emailList.toArray(新的String [emailList.size()));
}
email.putExtra(android.content.Intent.EXTRA_SUBJECT,学科);
email.putExtra(android.content.Intent.EXTRA_TEXT,消息);

email.setType(信息/ RFC822);或email.setType(text / plain的);

startActivity(Intent.createChooser(电子邮件,选择电子邮件客户端));
 
Android 手机电子邮件配置方法

I'm a newbie in android. Please help me. I'm not able to send email to multiple recipients. Here is my code.

public class SendEmailActivity extends Activity{

EditText subject_ed,message_ed;
TextView subject_tv,message_tv;
Button send_btn;

 ArrayList<String> emailList;
 ArrayList<Integer> idList;
 int eventId;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contacts_email_sms_layout);
    setupViews();
    Intent intent = getIntent();
    Bundle b = intent.getExtras();
    eventId =  b.getInt("EventId");//event id
    idList = b.getIntegerArrayList("IdList");//list of Ids
    emailList = b.getStringArrayList("EmailList");//list of email ids
    buttonListeners();
}

public void setupViews()
{
    subject_ed = (EditText)findViewById(R.id.ed_subject_email);
    message_ed = (EditText)findViewById(R.id.ed_msg_body);
    subject_tv = (TextView)findViewById(R.id.tv_subject_email);
    message_tv = (TextView)findViewById(R.id.tv_msg_body);
    send_btn = (Button)findViewById(R.id.btn_send_sms_email);
}               

public void buttonListeners()
{
    send_btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), "Email sent",Toast.LENGTH_LONG).show();
            // String to = textTo.getText().toString();
              String subject = subject_ed.getText().toString();
              String message = message_ed.getText().toString();
            Object[] to =  emailList.toArray();
//            for(int i = 0; i<=emailList.size(); i++)
////                  {
////                      
//                  String  to=   emailList.get(0);
////                     
////                  }



              Intent email = new Intent(Intent.ACTION_SEND);
              for(int i = 0; i < to.length; i++)
                {
                    Log.i("String is", (String)to[i]);
                    //String[] str = (String[])to[i];
                     email.putExtra(Intent.EXTRA_EMAIL,",'" +(String)to[i] + "'");
                }

              email.putExtra(Intent.EXTRA_SUBJECT, subject);
              email.putExtra(Intent.EXTRA_TEXT, message);

              //need this to prompts email client only
              email.setType("message/rfc822");

              startActivity(Intent.createChooser(email, "Choose an Email client :"));
             // finish();
        }
    });
}

}

解决方案

First your conversion from List to String[] is wrong you need to do as follows..

List<String> list = new ArrayList<String>();
String[] arrayOfStrings = list.toArray(new String[list.size()]);

And next thing is you need to mention android.Content.Intent as follows..

So finally you need to change as follows

ArrayList<String> emailList;
emailList = b.getStringArrayList("EmailList");
String[] emailArray;
Intent email = new Intent(android.content.Intent.ACTION_SEND);
for(int i = 0; i < to.length; i++){
Log.i("String is", (String)to[i]);
email.putExtra(android.content.Intent.EXTRA_EMAIL,emailList.toArray(new String[emailList.size()]));
}
email.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
email.putExtra(android.content.Intent.EXTRA_TEXT, message);

email.setType("message/rfc822"); or email.setType("text/plain");

startActivity(Intent.createChooser(email, "Choose an Email client :"));