Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

geoldr

macrumors newbie
Original poster
Apr 1, 2011
17
0
Hey guys, I am having difficulty opening the Mail app and sending a message. I have it to the point where it opens the app, opens the new message dialog, puts in the Subject, and the Body, but when there is a space in the body, it doesnt do anything. Here is code:

Code:
    NSString *emailMail = @"mailto:?subject=mySubject&body=";
    NSString *emailURL = [testU stringValue];
    NSString *emailSIG = @"Sig";
    NSString *URLFinal = [NSString stringWithFormat:@"%@%@%@", emailMail, emailURL, emailSIG];
    NSLog(@"%@",URLFinal);
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:george1]];

This will work without a problem. But say I change:

Code:
NSString *URLFinal = [NSString stringWithFormat:@"%@%@%@", emailMail, emailURL, emailSIG];
to this:
Code:
NSString *URLFinal = [NSString stringWithFormat:@"%@%@\n%@", emailMail, emailURL, emailSIG];

It will not work. Is there any way to do this ?

I was thinking maybe there is a way to do this with AppleScript and have it not even open the mail program, but I am not sure how to do this.
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
You're forming a URL, so the URL needs be properly encoded. For example, a space needs to be encoded as %20. But don't do this manually, use NSString's stringByAddingPercentEscapesUsingEncoding:
 

geoldr

macrumors newbie
Original poster
Apr 1, 2011
17
0
The blog post was from 2 years ago!!!

Right, but judging by the comments, since there was one from yesterday, and January 2011, I figured there is still a bug.

And actually, this code did work for me. Because using the default apple code it wouldn't encode the & in URLs and it would mess up my program. But using the code from the blog post it works!
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.