Tuesday, January 29, 2013

Sending Email In Android

In Android we can send Email  using following Code

                         Intent i = new Intent(Intent.ACTION_SEND);
                                 i.setType("message/rfc822");
                                 i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recieveremail@gmail.com"});
                                 i.putExtra(Intent.EXTRA_SUBJECT, "Subject of Mail");
                                 i.putExtra(Intent.EXTRA_TEXT   , "The Message Body");
                                 try {
                                           startActivity(Intent.createChooser(i, "Sending mail..."));
                                         
                                   }
                                 finally {
                                     

                                          // Code to execute when unable to send Email
                                      }



5 comments:

  1. Hello

    Could you also tell us how to mail attachments?

    ReplyDelete
    Replies
    1. To attache files in Email yuu need to use Intent.EXTRA_STREAM

      For Ex:

      ArrayList uris = new ArrayList();

      i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      startActivityForResult(Intent.createChooser(i, "Sending multiple attachment"), 12345);

      Delete
  2. Hi.
    Can you please tell how to send mail directly from the app.. without using any mail client.
    Regards.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Please anyone can tell how to send mails from app....without client interference. ...please

    ReplyDelete