Re: [NEWBIE] How to send an email with Cocoa?
Re: [NEWBIE] How to send an email with Cocoa?
- Subject: Re: [NEWBIE] How to send an email with Cocoa?
- From: Dale Gillard <email@hidden>
- Date: Thu, 28 Oct 2004 21:12:42 +1000
On Wed, 27 Oct 2004 11:05:47 +0100, Quinn wrote:
At 17:10 +1000 27/10/04, Igor Couto wrote:
1) Is there a way, from inside Cocoa, to create a new email message?
Is there a way to get the user's default email client to handle the
sending of the message?
The easiest way to do this is with a 'GURL' Apple event. The easiest
way to send such an event is via Launch Service's. The following
code does the trick, assuming that urlField is connected to an
NSTextField containing the URL.
- (IBAction)doIt:(id)sender
{
OSStatus err;
NSURL * url;
assert(urlField != nil);
url = [NSURL URLWithString:[urlField stringValue]];
assert(url != nil);
err = LSOpenCFURLRef( (CFURLRef) url, NULL);
assert(err == noErr);
}
After reading this it occurred to me that NSWorkspace's openURL class
method might do this too. Amazingly, it does! So here's a 1 line Cocoa
method to create an email msg in the user's default client (using
Quinn's example mailto: URL).
[[NSWorkspace sharedWorkspace] openURL: [NSURL
URLWithString:@"mailto:email@hidden?
subject=Hello Cruel World&body=Share and Enjoy."]];
PS It's nice to see an almost all Australian thread happening ;-)
Cheers.
Dale Gillard
dmg software
-------------------------------------------------------
Try Sidekick, a Mac OS X menu bar item
for AppleWorks 6. For more info pls visit:
<http://www.geocities.com/dmgsoftware>
-------------------------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden