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: Thu, 28 Oct 2004 11:11:43 +0100
At 9:38 +1000 28/10/04, Igor Couto wrote:
How do I create a message with ATTACHMENTS?
Ah. Much trickier.
Once again, thank you very much for that hint. I did not want to use
'Launch Services', as it is part of the Carbon framework, and not
Cocoas.
Actually, Launch Services is part of Application Services, which is a
common application-level framework that underlies both Cocoa and
Carbon. There's absolutely no reason not to call Launch Services
from a Cocoa application.
However, your hint put me on the right track. In Cocoa, the
NSWorkspace class has a method (-openURL:) that does basically the
same thing.
Indeed. I'm turning my answer into a Q&A for the developer web site.
As part of that work I moved it over to NSWorkspace.
Note that much of NSWorkspace is implemented in terms of Launch Services.
I had not even tried using it, because according to Apple's
documentation, NSURL understands only URLs compliant with RFCs 1808,
1738 and 2732 (the ipV6 extension). Reading RFC 1738 - the one that
specified format for the 'mailto' schema - we see that all the
specification supports is the *simplest* form of the schema - ie,
specifying *only* the address, but no other parts of the message.
Because of that, I did not even bother to try! - silly me... :-P
The smarts to understand RFC 2368 compliant URLs are all in the
receiving application. NSURL -> NSWorkspace -> Launch Services just
passes the URL text to the email application, which is responsible
for pulling apart the URL properly. It's up to the application to
parse it and extract the relevant fields. I tested this with Eudora,
Mail.app, and Entourage, and they all do this properly. Of course,
your user might be running a mail program that doesn't do this.
So, I'm almost there. The only part of the task that I still cannot
do is: attach a file to the message! How can I do that?
And that's where things fall apart. Alas, there's no way to specify
an attachment using RFC 2368. This leaves you with Mac-specific
solutions.
The underlying technology for opening a URL is the 'GURL' Apple event
suite. While that suite's specification...
<ftp://ftp.stairways.com/other/url-ae-standard-1-1-info.txt>
... describes an optional parameter for attaching files, this
parameter is not widely supported (for example, it's supported by
Eudora, but not by Mail.app <rdar://problem/3855958> or Entourage).
Therefore, if you need to send an attachment, the only solution is to
script the user's email client. DTS Q&A QA1018, 'Using AppleScript
to send an email with an attachment' shows how to do this for
Mail.app.
<http://dts.apple.com/qa/qa2001/qa1018.html>
Unfortunately it's different in each email client.
On the question of how run an AppleScript from within a Cocoa
application, that's best asked on a Cocoa programming list.
<http://lists.apple.com/cocoa-dev/>
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