Using AsyncTask to Send Android Email

后端 未结 2 1643
野趣味
野趣味 2020-12-11 05:18

I had recently asked a question regarding the following code:

Sending Email in Android using JavaMail API without using the default/built-in app

I had asked

相关标签:
2条回答
  • 2020-12-11 05:31

    There is a pretty good example right on the AsyncTask doc page.

    Pass your GMailSender object in to an AsyncTask, and call GMailSender#sendMail during doInBackground.

    That is,

    public void onClick(View v) {
        final GMailSender sender = new GMailSender("username@gmail.com", "password");
        new AsyncTask<Void, Void, Void>() {
            @Override public Void doInBackground(Void... arg) {
                try {   
                    sender.sendMail("This is Subject",   
                        "This is Body",   
                        "user@gmail.com",   
                        "user@yahoo.com");   
                } catch (Exception e) {   
                    Log.e("SendMail", e.getMessage(), e);   
                } 
            }
        }.execute();
    
    }
    
    0 讨论(0)
  • 2020-12-11 05:46
    public void onClick(View v) {
    final GMailSender sender = new GMailSender("username@gmail.com",       "password");
    new AsyncTask<Void, Void, Void>() {
        @Override public Void doInBackground(Void... arg) {
            try {   
                sender.sendMail("This is Subject",   
                    "This is Body",   
                    "user@gmail.com",   
                    "user@yahoo.com");   
            } catch (Exception e) {   
                Log.e("SendMail", e.getMessage(), e);   
            } 
        return null;}
    }.execute();
    
    }
    

    Thank you "dokkaebi"

    0 讨论(0)
提交回复
热议问题