How to put mailto html body with lwc?

442    Asked by DavidEdmunds in Salesforce , Asked on Feb 28, 2023

I create a quick action button to open the outlook app. and behind the scene I Am using LWC Headless Action to make it happen. and the following code is my complete lwc


TestSendEmail.html


 
TestSendEmail.js
import { api, LightningElement } from 'lwc';
export default class TestSendEmail extends LightningElement {
    @api invoke() {    
        var uri = "mailto:?subject=Test subject"+"&body="+encodeURIComponent("
Test Html
");
        console.log("show uri: ", uri);
        var a = document.createElement("a");
        a.href = uri;
        a.click();        
    }
}
TestSendEmail.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>

    54.0
    true
    
        lightning__RecordAction
    
    
        
            Action
        
    

And here the button after added to page layout:

The goal is only to open an outlook app with correctly rendered HTML. Hope someone can help me fix this issue.

Answered by Dipika Agarwal

Unfortunately, you can't put mailto html body with lwc.


  RFC 2368 states:

The special hname "body" indicates that the associated hvalue is the

body of the message. The "body" hname should contain the content for

the first text/plain body part of the message. ...

(Emphasis added).

In other words, HTML just isn't allowed in the body, or anywhere else, in the mailto protocol.

It goes on to say: ... The mailto URL is

primarily intended for generation of short text messages that are

actually the content of automatic processing (such as "subscribe"messages for mailing lists), not general MIME bodies.

Therefore, the rationale is that the mailto protocol is not suitable for composing complicated/encoded messages.


Your Answer

Interviews

Parent Categories