no_profile
no_profile

Reputation: 374

How can I make email sent from android java?

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

Upvotes: 0

Views: 145

Answers (3)

Jakir Hossain
Jakir Hossain

Reputation: 3930

You can try the following way.

      String[] recipients = {"[email protected]"};
      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.

Upvotes: 0

Mohd Faizan
Mohd Faizan

Reputation: 110

I think you can send email via Intent action

     Intent it = new Intent(Intent.ACTION_SEND);
     it.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
     it.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Tutlane");
     it.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Tutlane Tutorial Site");
     it.setType("message/rfc822");

Upvotes: 0

Mohammed Alloboany
Mohammed Alloboany

Reputation: 129

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())
);

Upvotes: 1

Related Questions