mailto link with HTML body

HtmlEmailMailto

Html Problem Overview


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

<a href="mailto:etc...">

Can I insert HTML formatted body in the mailto: part of the href?

<a href="mailto:me@me.com?subject=Me&body=<b>ME</b>">Mail me</a>

Note that (2016) in iOS, it is perfectly fine to add <i> and <b> tags for simple italic, bold formatting.

Html Solutions


Solution 1 - Html

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.

Solution 2 - Html

Whilst it is NOT possible to use HTML to format your email body you can add line breaks as has been previously suggested.

If you are able to use javascript then "encodeURIComponent()" might be of use like below...

var formattedBody = "FirstLine \n Second Line \n Third Line";
var mailToLink = "mailto:[email protected]?body=" + encodeURIComponent(formattedBody);
window.location.href = mailToLink;

Solution 3 - Html

No. This is not possible at all.

Solution 4 - Html

It's not quite what you want, but it's possible using modern javascript to create an EML file on the client and stream that to the user's file system, which should open a rich email containing HTML in their mail program, such as Outlook:

https://stackoverflow.com/a/27971771/8595398

Here's a jsfiddle of an email containing images and tables: https://jsfiddle.net/seanodotcom/yd1n8Lfh/

HTML

<!-- https://jsfiddle.net/seanodotcom/yd1n8Lfh -->
<textarea id="textbox" style="width: 300px; height: 600px;">
To: User <[email protected]>
Subject: Subject
X-Unsent: 1
Content-Type: text/html

<html>
<head>
<style>
    body, html, table {
        font-family: Calibri, Arial, sans-serif;
    }
    .pastdue { color: crimson; }
    table {
    	border: 1px solid silver;
    	padding: 6px;
    }
    thead {
        text-align: center;
        font-size: 1.2em;
        color: navy;
        background-color: silver;
        font-weight: bold;
    }
    tbody td {
    	text-align: center;
    }
</style>
</head>
<body>
<table width=100%>
	<tr>
		<td><img src="http://www.laurell.com/images/logo/laurell_logo_storefront.jpg" width="200" height="57" alt=""></td>
		<td align="right"><h1><span class="pastdue">PAST DUE</span> INVOICE</h1></td>
	</tr>
</table>
<table width=100%>
	<thead>
		<th>Invoice #</th>
		<th>Days Overdue</th>
		<th>Amount Owed</th>
	</thead>
	<tbody>
	<tr>
		<td>OU812</td>
		<td>9</td>
		<td>$4395.00</td>
	</tr>
	<tr>
		<td>OU812</td>
		<td>9</td>
		<td>$4395.00</td>
	</tr>
	<tr>
		<td>OU812</td>
		<td>9</td>
		<td>$4395.00</td>
	</tr>
	</tbody>
</table>
</body>
</html>
</textarea> <br>
<button id="create">Create file</button><br><br>
<a download="message.eml" id="downloadlink" style="display: none">Download</a>

Javascript

(function () {
var textFile = null,
  makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }
    textFile = window.URL.createObjectURL(data);
    return textFile;
  };

  var create = document.getElementById('create'),
    textbox = document.getElementById('textbox');
  create.addEventListener('click', function () {
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile(textbox.value);
    link.style.display = 'block';
  }, false);
})();

Solution 5 - Html

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>

Solution 6 - Html

Some things are possible, but not all, say for example you want line breaks, instead of using <br />use %0D%0A

Example:

<a href="mailto:?subject=&body=Hello,%0D%0A%0D%0AHere is the link to the PDF Brochure.%0D%0A%0D%0ATo view the brochure please click the following link: http://www.uyslist.com/yachts/brochure.pdf"><img src="images/email.png" alt="EMail PDF Brochure" /></a>                        
                 			

Solution 7 - Html

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.

Solution 8 - Html

Thunderbird supports html-body: mailto:[email protected]?subject=Me&html-body=<b>ME</b>

Solution 9 - Html

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGxGView Question on Stackoverflow
Solution 1 - HtmlAlfonso MarinView Answer on Stackoverflow
Solution 2 - HtmlOliver PearmainView Answer on Stackoverflow
Solution 3 - HtmlQuentinView Answer on Stackoverflow
Solution 4 - HtmlMatthewView Answer on Stackoverflow
Solution 5 - HtmlAndyView Answer on Stackoverflow
Solution 6 - HtmlStephen KaufmanView Answer on Stackoverflow
Solution 7 - HtmlAndrew FerrierView Answer on Stackoverflow
Solution 8 - HtmlPeterView Answer on Stackoverflow
Solution 9 - HtmlMiguel BallénView Answer on Stackoverflow