tags:

views:

658

answers:

3

I am writing an application for the Android. How do I send email from it?

+10  A: 

The best (and easiest) way is to use an Intent:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

Otherwise you'll have to write your own client.

fiXedd
+1  A: 

Sending email can be done with Intents which will require no configuration. But then it will require user interaction and the layout will be a bit restricted.

Build and sending a more complex email without user interaction entails building your own client. The first thing is that the Sun Java API for email are unavailable. I have had success leveraging the Apache Mime4j library to build email. All based on the docs at nilvec.

Rene
A: 

Hi. In my application, on click of button I have written code to send email. When I click the button it shows me the email which will be sent(to my email id) and when i click on send, it shows me "Sending message...". But the problem is I don't get the emails :( . Please let me know if i am missing out on something. Also do I have to set any permissions for doing this in my application?

Parimal Modi