Reputation: 453
I'm looking to program a button in my mac app to open the default email client and compose a new email with a pre-programmed address and subject.
The ideal functionality I am looking for is the same behaviour as that of the mailto: function when you click on an email address in safari.
I'd be grateful if someone could point me in the direction of some code that might work, or provide me with an example.
Many thanks.
Upvotes: 3
Views: 1071
Reputation: 410662
You can create a URL and open it:
- (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:[email protected]"
"?subject=Hello%20Cruel%20World!"
"&body=Share%20and%20Enjoy"
];
assert(url != nil);
// Open the URL.
(void) [[NSWorkspace sharedWorkspace] openURL:url];
}
Apple has more of an explanation in this technote.
Upvotes: 4