mailto link with HTML body

前端 未结 10 1915
攒了一身酷
攒了一身酷 2020-11-21 22:26

I have a couple of mailto links in a HTML document.


Can I insert HTML formatted body in the <

相关标签:
10条回答
  • 2020-11-21 23:02

    I have used this and it seems to work with outlook, not using html but you can format the text with line breaks at least when the body is added as output.

    <a href="mailto:email@address.com?subject=Hello world&body=Line one%0DLine two">Email me</a>
    
    0 讨论(0)
  • Anybody can try the following (mailto function only accepts plaintext but here i show how to use HTML innertext properties and how to add an anchor as mailto body params):

    //Create as many html elements you need.
    
    const titleElement = document.createElement("DIV");
    titleElement.innerHTML = this.shareInformation.title; // Just some string
    
    //Here I create an <a> so I can use href property
    const titleLinkElement = document.createElement("a");
    titleLinkElement.href = this.shareInformation.link; // This is a url
    

    ...

    let mail = document.createElement("a");
    
    // Using es6 template literals add the html innerText property and anchor element created to mailto body parameter
    mail.href = 
      `mailto:?subject=${titleElement.innerText}&body=${titleLinkElement}%0D%0A${abstractElement.innerText}`;
    mail.click();
    
    // Notice how I use ${titleLinkElement} that is an anchor element, so mailto uses its href and renders the url I needed
    
    0 讨论(0)
  • 2020-11-21 23:05

    As you can see in RFC 6068, this is not possible at all:

    The special <hfname> "body" indicates that the associated <hfvalue> is the body of the message. The "body" field value is intended to contain the content for the first text/plain body part of the message. The "body" pseudo header field is primarily intended for the generation of short text messages for automatic processing (such as "subscribe" messages for mailing lists), not for general MIME bodies.

    0 讨论(0)
  • 2020-11-21 23:05

    No. This is not possible at all.

    0 讨论(0)
  • 2020-11-21 23:07

    It is worth pointing out that on Safari on the iPhone, at least, inserting basic HTML tags such as <b>, <i>, and <img> (which ideally you shouldn't use in other circumstances anymore anyway, preferring CSS) into the body parameter in the mailto: does appear to work - they are honored within the email client. I haven't done exhaustive testing to see if this is supported by other mobile or desktop browser/email client combos. It's also dubious whether this is really standards-compliant. Might be useful if you are building for that platform, though.

    As other responses have noted, you should also use encodeURIComponent on the entire body before embedding it in the mailto: link.

    0 讨论(0)
  • 2020-11-21 23:12

    Thunderbird supports html-body: mailto:me@me.com?subject=Me&html-body=<b>ME</b>

    0 讨论(0)
提交回复
热议问题