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: Quinn <email@hidden>
- Date: Wed, 27 Oct 2004 11:05:47 +0100
At 17:10 +1000 27/10/04, Igor Couto wrote:
I need to be able to send an email from inside my Cocoa application.
Rather than having to deal with network communications directly -
and reinvent the wheel - I thought it might be easier to simply
create a new email message,
The Cocoa-based Message framework will let you send messages
directly. So, you can avoid the user's email client if you want to.
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);
}
An example of the extended mailto URL format is:
<mailto:email@hidden?subject=Hello Cruel World&body=Share and Enjoy.>.
A quick Internet search reveals detailed information, such as:
<http://www.utoronto.ca/ian/books/html4ed/chap8/mail.html>
Launch Services automatically targets the user's preferred mail
client. I tested the above URL with Mail.app (on 10.3.x) and Eudora,
and they both handle it fine. YMMV on other mail clients. Still,
it's better than trying to come up with a script that works with all
mail clients.
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
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