如何从我的应用程序中启动Mail.app中的“新建消息”窗口

时间:2011-07-12 06:59:15

标签: objective-c cocoa macos

我可以使用该命令启动Mail.app  [[NSWorkspace sharedWorkspace] launchApplication:@“Mail.app”];

但我想在Mail.app中启动新的消息窗口而不是整个Mail.app。我怎么能这样做?

1 个答案:

答案 0 :(得分:5)

我得到了答案

 NSString *encodedSubject = [NSString stringWithFormat:@"SUBJECT=%@", [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *encodedBody = [NSString stringWithFormat:@"BODY=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *encodedTo = [to stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *encodedURLString = [NSString stringWithFormat:@"mailto:%@?%@&%@", encodedTo, encodedSubject, encodedBody];
NSURL *mailtoURL = [NSURL URLWithString:encodedURLString];
[[NSWorkspace sharedWorkspace] openURL:mailtoURL];