iPhone mailto: links

326 views
Skip to first unread message

Dan Wood

unread,
Jul 6, 2007, 2:49:38 PM7/6/07
to iPhoneWebDev
I've just put in a mailto: link in TeleMoose that has a pre-filled subject and body.  What's interesting is that the body's content that you specify in the mailto link is actually interpreted as HTML, which is different than the standard (plain text), and how Apple Mail implements it.

So just be careful in generating a mailto: link; make sure that for the iphone, that you are generating HTML, not plain text -- e.g. for newlines, you'd use <br>; escape your < > & characters, etc.



--
Dan Wood


Sign up for a free 30-day trial and download 50 FREE songs from eMusic's catalogue of over 2 million DRM-free tracks:

Hardy Macia

unread,
Jul 6, 2007, 3:28:51 PM7/6/07
to iphone...@googlegroups.com
Ah, just in time... I had already given up on having new lines in the
body and filed a bug on it. Replacing \r \n with <br> works great.

Thanks
Hardy

Kalle Alm

unread,
Jul 6, 2007, 3:29:32 PM7/6/07
to iphone...@googlegroups.com
I've been working on an example page for "mailto:", and tried what you
said but I am having trouble figuring out how to escape <this>. The
phone keeps interpreting it as a tag and removes it from the email.

The example is here: http://www.iphonewebdev.com/examples/mailto.html

Ideas welcome!

-Kalle.

Dan Wood wrote:
> I've just put in a mailto: link in TeleMoose that has a pre-filled
> subject and body. What's interesting is that the body's content that you
> specify in the mailto link is actually interpreted as HTML, which is
> different than the standard (plain text), and how Apple Mail implements it.
>
> So just be careful in generating a mailto: link; make sure that for the
> iphone, that you are generating HTML, not plain text -- e.g. for
> newlines, you'd use <br>; escape your < > & characters, etc.
>
>
>
> --
> Dan Wood

> dw...@karelia.com <mailto:dw...@karelia.com>

Kalle Alm

unread,
Jul 6, 2007, 3:41:15 PM7/6/07
to iphone...@googlegroups.com
Got it. %26lt;, %26gt; etc. worked.

-Kalle.

Dan Wood

unread,
Jul 6, 2007, 4:36:52 PM7/6/07
to iphone...@googlegroups.com
Ah, good catch. The trick is that special characters need to be
escaped both for a URL and for the HTML page.

I get this by starting with the HTML, meaning that there are tags,
and I've escaped & < > .... Then I url-encode the string (changing
space to %20, & to %26, < to %3C, > to %3F, etc. And then, for good
measure, I escape any entities to put that string into the web page
(though that is not strictly necessary since all the & < > characters
have already been converted).

For example, this chunk of HTML....

Check this out!<br><br>Harry Potter and the Deathly Hallows (Book 7)
by J. K. Rowling.<br><br>&lt;http://www.amazon.com/o/ASIN/0545010225/
karelsofwa-20&gt;<br><br>... or from your iPhone, &lt;http://
TeleMoose.com/d_0545010225&gt;

becomes....

Check%20this%20out%21%3Cbr%3E%3Cbr%3EHarry%20Potter%20and%20the%
20Deathly%20Hallows%20%28Book%207%29%20by%20J.%20K.%20Rowling.%3Cbr%3E
%3Cbr%3E%26lt%3Bhttp%3A%2F%2Fwww.amazon.com%2Fo%2FASIN%2F0545010225%
2Fkarelsofwa-20%26gt%3B%3Cbr%3E%3Cbr%3E...%20or%20from%20your%20iPhone
%2C%20%26lt%3Bhttp%3A%2F%2FTeleMoose.com%2Fd_0545010225%26gt%3B


On Jul 6, 2007, at 12:41 PM, Kalle Alm wrote:

>
> Got it. %26lt;, %26gt; etc. worked.
>
> -Kalle.
>

--
Dan Wood

Hardy Macia

unread,
Jul 6, 2007, 10:06:58 PM7/6/07
to iphone...@googlegroups.com
I used encodeURIComponent

Sent from my iPhone

Kalle Alm

unread,
Jul 7, 2007, 6:24:01 AM7/7/07
to iphone...@googlegroups.com
Good point. I'll add a note about that to the example page.

-Kalle.

Reply all
Reply to author
Forward
0 new messages