Sunday, March 20, 2011

Cocoa - specify content type in mailto URLs to include HTML

Hi

I want to open the user's Mail client on clicking a button and populate the message body with some HTML content.

While my code successfully does that (using mailto: URL scheme), the HTML content shows up as is (i.e. the HTML is not formatted).

Is there a way I can specify that my message contains HTML when opening the Mail app? Or can I format my data like we do when typing an email in a mail client?

Thanks.

From stackoverflow
  • while specific extensions might be available on certain mailto handlers, the relevent text from RFC 2368 - The mailto URL scheme is

    The "body" hname should contain the content for the first text/plain body part of the message.


    The hname here refers to the 'body' in the 'body=some text' part of the mailto url. You basically get to provide a full set of email headers (name=value pairs) in the mailto url - separated by &'s - 'body' is defined specifically in the rfc to indicate the following text (up until the next separating '&') is the text/plain part of the message. Because there is no schema to add multiparts to an email message, you cannot express the multipart required to add the text/html part.

    The only way to add a text/html part to the message would require you to be using a mailto handler that either supported an extended uri syntax, or had some way to allow you to continue programmatically adding content to the email.

    lostInTransit : Read through the specs but couldn't really make out what you're referring to here by hname.
    Peter Hosey : Did you try ⌘F? “‘hname’ and ‘hvalue’ are encodings of an RFC 822 header name and value, respectively.”
    lostInTransit : Yes I did. And from what I could understand this would only work for to, cc, bcc, subject and body.
    Peter Hosey : Correct. Read the last paragraph of the answer.
  • I'm not sure about this, but just to give some input. RFC2368 Shows how to format mailto links, specifically how to include headers. One example of a header is "Content-type", which you would want to set to text/html in this case. So something like

    mailto:?Content-type=text/html
    

    might just work.

    lostInTransit : Nope. Doesn't work.
  • I answered that a couple days ago here: How can I send a HTML email from Cocoa?

0 comments:

Post a Comment