HaOx
HaOx

Reputation: 1879

How can I send an email to more than one email account?

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("[email protected]", "password");
                sender.sendMail("This is Subject",   
                        "This is Body",   
                        "[email protected]",   // This is not working                            
                        "[email protected]"); //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.

Upvotes: 2

Views: 182

Answers (2)

yaron
yaron

Reputation: 91

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

Upvotes: 2

Deepak
Deepak

Reputation: 2009

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

Upvotes: 0

Related Questions