How can I make email sent from android java?

September 11, 2019, at 11:10 AM

I have an POS app and I want to send my e-receipt to customers via email.

I have checked some resources and what I have found is how to send emails with text messages.

How can I make my email to look something like this?

Thank you for any answers that you can give.

Answer 1

I think you can send email via Intent action

     Intent it = new Intent(Intent.ACTION_SEND);
     it.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
     it.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Tutlane");
     it.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Tutlane Tutorial Site");
Answer 2

You can pass Spanned text in your extra

final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
Html.fromHtml(new StringBuilder()
    .append("<p><b>Some Content</b></p>")
    .append("<small><p>More content</p></small>")
Answer 3

You can try the following way.

      String[] recipients = {""};
      Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
      // prompts email clients only
      email.putExtra(Intent.EXTRA_EMAIL, recipients);
      email.putExtra(Intent.EXTRA_SUBJECT, "email subject");
      email.putExtra(Intent.EXTRA_TEXT, "Hello, This is a test message");
      try {
        // the user can choose the email client
         startActivity(Intent.createChooser(email, "Choose an email client from..."));
      } catch (android.content.ActivityNotFoundException ex) {
         Toast.makeText(MainActivity.this, "No email client installed.",

Android provides some further fields, these fields have to be attached to the Intent as extra data:

  • EXTRA_BCC: email addresses for blind carbon copy
  • EXTRA_CC: email addresses for carbon copy
  • EXTRA_HTML_TEXT: supply an alternative to EXTRA_TEXT as HTML formatted text
  • EXTRA_STREAM: URI holding a stream of data supplying the data that are sent
  • EXTRA_TITLE: the title that is shown when the user has to choose an email client

For a complete example, see this tutorial.

Hope it helps you, Happy Coding.