Hello. I am trying to send email intent from android via gmail or outlook with .html as a body. The ...
l
Hello. I am trying to send email intent from android via gmail or outlook with .html as a body. The reason to do that is to have a nicely prepared email template. Is that even possible? Everything I tried does not seem to work for gmail and it only displays plain HTML in body of email. Code in comments
1
not kotlin but kotlin colored 3
Copy code
fun sendTest(context: Context) {
    val htmlString: String = context.assets.open("email_invitation.html").bufferedReader().use { it.readText() }
    val intent = Intent(Intent.ACTION_SEND).apply {
        type = "text/html" // only email apps should handle this
        putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name))
        putExtra(Intent.EXTRA_TEXT, Html.fromHtml(htmlString))
    }
    context.startActivity(Intent.createChooser(intent, context.getString(R.string.app_name)))
}
a
This is not a Kotlin-specific question. See channel description for where such questions should go next time. Anyway, Gmail used to support this a long time back, but it hasn't for quite some time. It's entirely up to email clients how to handle
EXTRA_TEXT
. Nothing you can do, I think. Also, your intent should be
Intent(Intent.ACTION_SENDTO, "mailto:".toUri())
to restrict only to email apps.
1
l
Thanks for response. From pinned message I understood that everything else android related goes here. I am not going to discord or thirdparty places for that....
a
You're in the kotlinlang slack. I agree that the channel description and other entry points could be clearer, but it is what it is. If your question is unaffected by which language/framework you're coding in, then it doesn't fit here. Simple.
I am not going to discord or thirdparty places for that
Third party relative to what? Only one of the alternatives is a Discord server. Other two are Slack.
150 Views