• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [NEWBIE] How to send an email with Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: [NEWBIE] How to send an email with Cocoa?
      • From: Igor Couto <email@hidden>
References: 
 >[NEWBIE] How to send an email with Cocoa? (From: Igor Couto <email@hidden>)

  • Prev by Date: Re: [NEWBIE] How to send an email with Cocoa?
  • Next by Date: Re: Discover Question
  • Previous by thread: Re: [NEWBIE] How to send an email with Cocoa?
  • Next by thread: Re: [NEWBIE] How to send an email with Cocoa?
  • Index(es):
    • Date
    • Thread