0

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?

enter image description here

Nimantha
  • 6,405
  • 6
  • 28
  • 69
no_profile
  • 387
  • 5
  • 15
  • You can either construct the email content as HTML inside EXTRA_TEXT or Convert your content into a file (ex. pdf, csv, etc..) and send it as attachment – Renz Manacmol Sep 11 '19 at 03:11
  • I think this is duplicate, you can go through - https://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application – Faizzy Sep 11 '19 at 03:21
  • @MohdFaizan, I want a specific layout to be sent, and in this case is an invoice. Not just random texts. – no_profile Sep 11 '19 at 07:45
  • 1
    If you want to send an invoice clearly you need to either send HTML way or PDF format. But if this Implementation is for admin app then It will be good but if this is for individual user than I dont think Its good to send email via mobile app, you need to trigger server for email – Faizzy Sep 11 '19 at 08:37

3 Answers3

1

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");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
    .append("<p><b>Some Content</b></p>")
    .append("<small><p>More content</p></small>")
    .toString())
);
0

I think you can send email via Intent action

     Intent it = new Intent(Intent.ACTION_SEND);
     it.putExtra(Intent.EXTRA_EMAIL, new String[]{"support@tutlane.com"});
     it.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Tutlane");
     it.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Tutlane Tutorial Site");
     it.setType("message/rfc822");
Faizzy
  • 112
  • 7
0

You can try the following way.

      String[] recipients = {"abc@gmail.com"};
      Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
      // prompts email clients only
      email.setType("message/rfc822");
 
      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.",
                 Toast.LENGTH_LONG).show();
      }
   }

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29