1

There are a lot of questions and answer about this topic but none of them seems to work. I have search in Google about "send html email Android Java" and followed all links without success (from stackoverflow and from other sites). I want to send an HTML email from my android app and Gmail app. I use the next code to do it but I always get a text email:

Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, mysubject);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
StringBuilder sbContent = new StringBuilder();
sbContent.append("<p>Text <strong>with html</strong></p>");
emailIntent.putExtra(Intent.EXTRA_TEXT, HtmlCompat.fromHtml(sbContent.toString(), HtmlCompat.FROM_HTML_MODE_LEGACY));
startActivity(Intent.createChooser(emailIntent, ""));

I've tried changing type to "text/plain", EXTRA_TEXT with EXTRA_HTML_TEXT, and some other attemps, but without success. Does anyone have an example of how to do it?

MMG
  • 3,226
  • 5
  • 16
  • 43
briast
  • 286
  • 4
  • 19
  • See the answer here: https://stackoverflow.com/a/2745702/3475551 It might help and refactor anything that might be deprecated. – Eaweb May 04 '20 at 16:01
  • Yes. I saw it but It doesn't work. Over the years unfortunately all answers about this seem to be outdated. It was my first attemp. – briast May 04 '20 at 16:16
  • Try searching for 'send html email from Java' – NomadMaker May 04 '20 at 16:42
  • I tried too. But thouse links can't be applied to java for Android. they use some jar files that aren't compatible with android. It's not the same. If you know anyone that works, please paste it here. Thanks. – briast May 04 '20 at 17:07
  • Because I haven't found a way to do it with Gmail app, I switched to [javaMail](https://javaee.github.io/javamail/Android) and send it directly. – briast May 05 '20 at 08:57

0 Answers0