2

From my android app I can send emails. But I can only send emails to one account. I was trying to modify the code in many different ways but I couldn't archive to send the email to more than one account.

I'm using this code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button send = (Button) this.findViewById(R.id.send);
    send.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            try {   
                GMailSender sender = new GMailSender("username@gmail.com", "password");
                sender.sendMail("This is Subject",   
                        "This is Body",   
                        "user@gmail.com",   // This is not working                            
                        "user@yahoo.com"); //This is working 
            } catch (Exception e) {   
                Log.e("SendMail", e.getMessage(), e);   
            } 

        }
    });

}

Here is the whole code: Sending Email in Android using JavaMail API without using the default/built-in app

Thanks.

Community
  • 1
  • 1
HaOx
  • 1,839
  • 6
  • 26
  • 36

2 Answers2

2
Intent actionIntent = new Intent(Intent.ACTION_SEND); 
actionIntent.setType("plain/text"); 
String emails ="";
for (int i = 0; i < emailAddress.size(); i++) {
emails=emails+";"+emailAddress.get(i);
}   
String emailAddressList[]={emails};             
actionIntent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);  
startActivity(actionIntent); 

This works for me for launching email application and attaching all the To addresses You can add your subject like this: actionIntent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject");

Hope this will help you. Regards, Yaron

yaron
  • 91
  • 1
  • 4
0

add this to your code, this is that what you want.

String[] recipients = new String[] { "email addresses"};
            for (String string : recipients) {

                GmailSender sender = new GmailSender("yourmailAccount",
                        "password");
                try {
                    sender.sendMail("This is Subject", "This is Body",
                            "NameOfSender", string);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
        }
Deepak
  • 1,989
  • 1
  • 18
  • 20