Xcode 如何获取safari邮件:mac应用程序的行为?

Xcode 如何获取safari邮件:mac应用程序的行为?,xcode,cocoa,Xcode,Cocoa,我想在我的mac应用程序中设置一个按钮,打开默认的电子邮件客户端,然后用预先设置好的地址和主题撰写一封新的电子邮件 我正在寻找的理想功能与在safari中单击电子邮件地址时的mailto:功能相同 如果有人能为我指出一些可能有效的代码的方向,或者给我举个例子,我将不胜感激 非常感谢。您可以创建URL并打开它: - (IBAction)sendMailCocoa:(id)sender // Create a mail message in the user's preferred mail

我想在我的mac应用程序中设置一个按钮,打开默认的电子邮件客户端,然后用预先设置好的地址和主题撰写一封新的电子邮件

我正在寻找的理想功能与在safari中单击电子邮件地址时的mailto:功能相同

如果有人能为我指出一些可能有效的代码的方向,或者给我举个例子,我将不胜感激


非常感谢。

您可以创建URL并打开它:

- (IBAction)sendMailCocoa:(id)sender
    // Create a mail message in the user's preferred mail client 
    // by opening a mailto URL. The extended mailto URL format 
    // is documented by RFC 2368 and is supported by Mail.app 
    // and other modern mail clients.
    //
    // This routine's prototype makes it easy to connect it as 
    // the action of a user interface object in Interface Builder.
{
    NSURL *     url;

    // Create the URL.

    url = [NSURL URLWithString:@"mailto:dts@apple.com"
        "?subject=Hello%20Cruel%20World!"
        "&body=Share%20and%20Enjoy"
    ];
    assert(url != nil);

    // Open the URL.

    (void) [[NSWorkspace sharedWorkspace] openURL:url];
}
苹果对此有更多的解释