Saturday, April 14, 2012

How to Send Email without User Interaction (In Background) in Android ?

Android provide Intent to send the email. It compose email in Native Email editor and user need to click on Send button to send the email. It crease issue when application need to send more then one email. User will not click on send button 10 or 20 times.
To solve this issue. I found javaMail API implemented for Andorid.
I have create Demo project, attached with this article. JavaMail also allowed to send email with attachment and HTML as body content. JavaMail required email user name & password to send the email.
Code Snippet To Send Email
       Mail m = new Mail("", "<PASSWORD>");
        String[] toArr = {""};
        m.setFrom(" ");
        m.setSubject("This is an email sent using my Mail JavaMail wrapper from an Android device.");
        m.setBody("Email body");
        try {
          if(m.send()) {
            Toast.makeText(this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(this, "Email was not sent.", Toast.LENGTH_LONG).show();
        } catch(Exception e) {
          Log.e("MailApp", "Could not send email", e);

No comments:

Post a Comment