1

I am testing the following code on an iPhone4 (without sim card, but I don't see how that can matter since its mail program is otherwise working fine):

The SharedApplication and canOpenURL etc. are all routines provided by XE4.

procedure TFormMain.sbContactsDetailsEmailClick(Sender: TObject);
var
  S: string;
  NSU: NSUrl;
begin
 // URL.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding);
  S := 'mailto:' + 'info@example.com' + '?subject=' + 'title' + '&body=';
  NSU := StringToNSUrl(S);
  if SharedApplication.canOpenURL(NSU) then
    SharedApplication.openUrl(NSU)
  ;
end;

Unfortunately, it seems SharedApplication.canOpenURL(NSU) returns false. Am I doing anything wrong?

3
  • 1
    The doco says that openUrl confirms "another application will be launched to handle it" (the URL). If you enter your URL into a browser does it open an email client for example? Is an application associated with mailto?
    – Jason
    Aug 5, 2013 at 4:09
  • @Jason Just tested what you said, and yes, email program does pop up if I enter mailto:info@example.com into browser. (I also tested it with a subject added)
    – Tom
    Aug 5, 2013 at 9:36
  • Anyone feel free to make an answer, and I will award bounty
    – Tom
    Aug 10, 2013 at 9:23

1 Answer 1

2

I should have through of it myself, but here goes:

do work

'mailto:info@example.com?subject=test'
'mailto:info@example.com?subject=test%20test'

does not work

'mailto:info@example.com?subject=test test'

(i.e. solution is to convert spaces to %20)

2
  • 1
    So you've just had to URL encode that string.
    – TLama
    Aug 8, 2013 at 4:27
  • 1
    Yep. Upvoted your comment since I should have included that info in my answer.
    – Tom
    Aug 8, 2013 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.