Re: Launch Email or Browser
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.