14

I have to bring up the outlook compose box when a button is pressed and the body should contain the image of a specific DIV. I am using html2canvas to capture the image, with mailto i am able to fire a outlook compose mail instance but seems mailto is for simple plain text and is not supporting to embed image in the mailbox.

Any ideas, thoughts?

Muthu
  • 265
  • 1
  • 6
  • 16
  • 1
    `Mailto` is extremely limited and can olny be used in the most simple of cases. This, unfortunatly, does not sound like a simple case. You may need to start investigating server side solutions. – Jon P Oct 15 '14 at 03:36
  • There's a way to do this if you can use a C# application. But not with HTML/JavaScript. See my answer (C# solution not included there). – sampathsris Oct 15 '14 at 04:47

1 Answers1

19

TL;DR: You cannot do this.


You can use Data URI Scheme to embed an image in HTML. If an emails MIME type is text/html you can do the same. You will have to encode your image with a suitable encoding (e.g.: base64).

For example:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

However, you cannot include HTML in the body part of the mailto: URL. The content of the body parameter is considered plain-text as per RFC 2368.

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. 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.

So if you use a URL encoded HTML as the body parameter of a mailto: URL, here is what happens:

<a href="mailto:email@domain.com?subject=Check%20this%20out!&body=%3Cp%3EHi%3C%2Fp%3E%3Cimg%20src%3D%22data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4%2F%2F8%2Fw38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg%3D%3D%22%20alt%3D%22Red%20dot%22%20%2F%3E">Write Email!</a>

Result:

New Outlook mail message

Community
  • 1
  • 1
sampathsris
  • 21,564
  • 12
  • 71
  • 98
  • 2
    this is a good answer! Sorry to OP that there's no way to do what you're after. – Patrick Moore Oct 15 '14 at 16:41
  • Yea, so the image itself will not be there in the body right, only some HTML code will be present? – Muthu Oct 15 '14 at 17:41
  • @Muthu: Yes, but you can perfectly do this with a C# application, if that matches your requirements. – sampathsris Oct 16 '14 at 00:57
  • This is strange. Running this in Thunderbird actually works, but it won't work in outlook. @Krumia Do you have any idea? – kabirbaidhya Apr 26 '18 at 19:47
  • @kabirbaidhya: It should not work actually. Because as per RFC 2368, body can only be plain text. Thunderbird is doing a smart thing, but that's non-compliant. You should not rely on it. – sampathsris Apr 27 '18 at 04:03
  • Yes, I know it's not on spec and isn't reliable. Strange that thunderbird got it working. – kabirbaidhya May 07 '18 at 22:52