• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Launch Email or Browser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launch Email or Browser


  • Subject: Re: Launch Email or Browser
  • From: John Nairn <email@hidden>
  • Date: Fri, 17 May 2002 16:09:26 -0600

The method to launch an email (from below) with addressee, subject, and
body works fine using:

[[NSWorkspace sharedWorkspace] openURL:[NSURL
URLWithString:@"mailto:email@hidden?subject=A Subject&body=A URL Encoded Body.
"]];

The text in the body, however, needs to have escape sequences for
several characters which can be accomplished with the following code:

myMsg=[[NSMutableString alloc] initWithString:[myProduct theMsg]];
[self replaceString:@":" withString:@":" inString:myMsg];
[self replaceString:@"/" withString:@"/" inString:myMsg];
[self replaceString:@"@" withString:@"@" inString:myMsg];
[self replaceString:@"#" withString:@"#" inString:myMsg];
[self replaceString:@";" withString:@";" inString:myMsg];
[self replaceString:@"%" withString:@"%" inString:myMsg];
[self replaceString:@" " withString:@" " inString:myMsg];
[self replaceString:@"\n" withString:@" " inString:myMsg];

where replaceString is

- (void)replaceString:(NSString *)lookFor withString:(NSString
*)replaceWith
inString:(NSMutableString *)aString
{
NSRange range;

while(YES)
{ range=[aString rangeOfString:lookFor options:NSLiteralSearch];
if(range.location==NSNotFound) break;
[aString replaceCharactersInRange:range withString:replaceWith];
}
}

but there is one problem. I found out that the length of the string
passed to openURL is limited to 1023 characters and 1 termination
character. Anything longer and Mail (my email choice) does not respond
to the URL.

Does anyone know if this is a limit of the Mail application or of URL
definitions in general?

On Thursday, May 16, 2002, at 01:21 PM, Ryan Stevens wrote:

> On Thursday, May 16, 2002, at 11:47 AM, Douglas Davidson wrote:
>
>> On Thursday, May 16, 2002, at 11:11 AM, John Nairn wrote:
>>
>>> I want to launch email program (with message started to person with
>>> subject and body filled in) and to launch a browser to open a web
>>> site. I assume it is easy, but browsing through Apple's documention,
>>> I am not sure where to look. Is there sample code? Or what NSObject
>>> is used?
>>>
>>
>> I would suggest trying -[NSWorkspace openURL:].
>>
> More specifically, try...
>
> [[NSWorkspace sharedWorkspace] openURL:[NSURL
> URLWithString:@"mailto:email@hidden?subject=A Subject&body=A URL Encoded Body.
> "]];
>
> And...
>
> [[NSWorkspace sharedWorkspace] openURL:[NSURL
> URLWithString:@"http:// ... "]];
>
>
----------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page: http://www.mse.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Launch Email or Browser
      • From: Douglas Davidson <email@hidden>
    • Re: Launch Email or Browser
      • From: Rosyna <email@hidden>
    • Re: Launch Email or Browser
      • From: Dan Crevier <email@hidden>
    • Re(2): Launch Email or Browser
      • From: Jens Bauer <email@hidden>
References: 
 >Re: Launch Email or Browser (From: Ryan Stevens <email@hidden>)

  • Prev by Date: Dos anybody now how to use "setUsesThreadedAnimation" NSProgressIndicator control.
  • Next by Date: Re: Cocoa Logo
  • Previous by thread: Re: Launch Email or Browser
  • Next by thread: Re(2): Launch Email or Browser
  • Index(es):
    • Date
    • Thread