Tuesday 26 July 2011

Send Mail Using Intent

You can send Mail Using one of Email Client installed on device.

Note: It will ask user to choose the email client and then user have to send it by himself /herself.

public void sendMail(Context context,String address){
        //Creating intent for sending mail....
        String[] recipients = new String[]{address,};
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("message/rfc822");
        emailIntent.putExtra( Intent.EXTRA_SUBJECT,"");      //Subject of message
        emailIntent.putExtra( Intent.EXTRA_TEXT,"");          //Body of message
        emailIntent.putExtra( android.content.Intent.EXTRA_EMAIL,recipients);
        try {
            context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        }catch (ActivityNotFoundException e) {
            Toast.makeText(context,"No Email Client Available.",Toast.LENGTH_SHORT).show();
        }
}

No comments:

Post a Comment