如何向多个电子邮件帐户发送电子邮件?

时间:2012-02-02 11:56:52

标签: android sendmail

从我的Android应用程序中,我可以发送电子邮件。但我只能向一个帐户发送电子邮件。我试图以多种不同的方式修改代码,但我无法存档以将电子邮件发送到多个帐户。

我正在使用此代码:

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

        }
    });

}

以下是整个代码:Sending Email in Android using JavaMail API without using the default/built-in app

感谢。

2 个答案:

答案 0 :(得分: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); 

这适用于启动电子邮件应用程序并附加所有To地址 您可以像这样添加主题:     actionIntent.putExtra(Intent.EXTRA_SUBJECT,“你的主题”);

希望这会对你有所帮助。 问候, 亚龙

答案 1 :(得分:0)

将此添加到您的代码中,这就是您想要的。

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();
            }
        }
相关问题