PDA

View Full Version : mailto URL with html issue




Labeno
Mar 30, 2009, 03:38 PM
I'm trying to figure out why the email client does not always start when using what looks like a valid html formatted mailto URL.

The app I created genrates HTML text on the fly similar to the following but much more information:
NSString *body = @"<html><body><h4>Greeting</h4><table><tr><td><b>Hi There!</b></td><td>this and that</td></tr></body></html>";

At this point, no encoding has been done yet to any spaces, ampersands, etc.

Then I use the following to finish composing it and send it to the email client:
NSString *encoded_body = [body2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *subject = [@"test email" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *mail_string = [NSString stringWithFormat:@"mailto:?subject=%@&body=%@", subject, encoded_body];
NSURL *url = [[NSURL alloc] initWithString:mail_string];
[[UIApplication sharedApplication] openURL:url];

For most of the customers it seems to work, but for many, the openUrl command does nothing (i.e the app does not exit and the email client does not start).
When I test the customer situation, I can duplicate the issue, but looking at the html, I can't find anything wrong.
If I randomly just comment out some part of the html, then it works sometimes, so then I'll uncomment it and comment something else out, and it still works. So what I'm finding is that it's not a particluar piece of html this is bad, it seems that all I have to do is just comment out some part of the html and then it will work.

My theory is it's not being encodeded properly, and commenting out part of the html changes something to allow the encoding to work on what's left of the body.

Anyway experience similar problems?
Is there an obvious step I'm missing?

Thanks



abyram
Mar 31, 2009, 11:39 PM
I've hit this with one of my apps. You can try using CFURLCreateStringByAddingPercentEscapes and that may or may not help. It worked for me until 2.2.1. If that doesn't work, I'm afraid you'll have to wait until Apple updates things or find another way to work around it. I submitted a bug on March 2nd 2009 (Bug #6635825) - but have yet to hear back from Apple (still shows as Open in bug reporter).

I have a blog post about (link below) it if you want more details, but that's the quick version.

http://blog.cogitu.com/2009/03/02/uiapplications-buggy-openurl-and-budgees-csv-export/

Labeno
Apr 1, 2009, 06:15 AM
Thanks abyram,
I feel a little better that it's not my code.
I also send a CSV and HTML version of the emails in my app.
I noticed the mailto is more reliable if I removed all double spaces, but it's still not 100%.
It very frustrating.

jnic
Apr 1, 2009, 07:16 AM
I noticed the mailto is more reliable if I removed all double spaces

mailtos shouldn't have spaces at all unless they're escaped.

Labeno
Apr 1, 2009, 07:53 AM
Sorry, I should have been more clear... Before encoding, I had places in the text that had two spaces. Then after encoding, it would sometimes fail. But if I got rid of muliple spaces before the encoding step, then it would be more reliable to get the mailto url to work.

It's all very wierd.