• 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: NSMailDelivery
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMailDelivery


  • Subject: Re: NSMailDelivery
  • From: David Phillip Oster <email@hidden>
  • Date: Fri, 13 May 2005 20:37:14 -0700

(Sorry for the errant posting, <Command>-E is programmed into my fingers to copy the selection to the Find dialog, but in this mailer, it appears to mean "Send".)

Last month, I was posting about my NSMailDelivery woes. Turns out, I had neglected to drag Message.framework into my project, and ZeroLink hid from me that I was calling undefined objects,

email@hidden has been very helpful, and email@hidden, if you write me directly, I may be of some help.

Here is a simple, tested, example of using NSMailDelivery:

[NSMailDelivery deliverMessage: @"This is my first test message.\nSent by NSMailDelivery.\n" subject: @"A Computer generated message." to: @"email@hidden"];

Pretty neat: e-mail in one line of Cocoa. (Replace the "to" address with a real one.)

Here is another way to do it:
This sends a message by opening a window in the user's mailer:

NSString *to = [[NSString stringWithString: @"David Phillip Oster <email@hidden>"] stringByPercentEscapesForMailtoURL];
NSString *subject = [[NSString stringWithString: @"First Automated Test"] stringByPercentEscapesForMailtoURL];
NSString *body = [[NSString stringWithString:
@"First Automated Test\nFirst Automated Test= & Will this foul up?\n(The e-mail includes special characters like %, '&' and \"?\" that the URL parser for mailto may balk at.)\n"] stringByPercentEscapesForMailtoURL];
NSString *emailURLString = [NSString stringWithFormat: @"mailto:%@?subject=%@&body=%@";, to, subject, body];
NSURL *emailURL = [NSURL URLWithString: emailURLString];
[[NSWorkspace sharedWorkspace] openURL:emailURL];


It needs this helper:


@interface NSString (PercentEscapesForURLs) - (NSString*) stringByPercentEscapesForMailtoURL; @end

@implementation NSString (PercentEscapesForURLs)

// wrap CFURLCreateStringByAddingPercentEscapes in Cocoa clothing.
- (NSString*) stringByPercentEscapesForMailtoURL
{
NSString *val = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef) self, CFSTR(""), CFSTR("=?&"), kCFStringEncodingUTF8);
return [val autorelease];
}


@end

I'm still looking for a good example of using NSMailDelivery with NSMIMEMailFormat to send a multipart mime mail with HTML and images that an e-mail client will proeprly parse.

Note:
NSMailDelivery gives you no indication of what went wrong, if something went wrong.
NSMailDelivery give you no status info: you don't know what it is doing for the few seconds
it is doing it.
NSMailDelivery is synchronous and blocks: you can't animate an indeterminate progress meter while it is running. You can't poll for the user canceling.



David Phillip Oster _______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Prev by Date: [ANN] IsingCocoa - simulation of the Ising model for ferromagnetic material
  • Next by Date: Re: FSCopyObjectAsync: useless and crippled
  • Previous by thread: Re: NSMailDelivery
  • Next by thread: CoreData: Data freshness vs. multithreading
  • Index(es):
    • Date
    • Thread