如何获取safari mailto:mac app的行为?

Rhy*_*wis 3 xcode cocoa

我想在我的mac应用程序中编写一个按钮来打开默认的电子邮件客户端,并编写一个带有预编程地址和主题的新电子邮件.

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

如果有人能指出我可能有用的代码,或者给我一个例子,我将不胜感激.

非常感谢.

mip*_*adi 5

您可以创建一个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];
}
Run Code Online (Sandbox Code Playgroud)

Apple在这个技术说明中有更多的解释.