Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mpemburn

macrumors member
Original poster
Jan 11, 2008
51
0
Bel Air, MD USA
Hi,

After doing some searching around, I'm not finding out how to detect which email client is the user's default. Any guidance in this?

Thanks in advance,

Mark
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Use LSGetApplicationForURL():

Code:
NSURL *mailtoURL = [NSURL URLWithString:@"mailto:"];
CFURLRef emailURL = NULL;
LSGetApplicationForURL((CFURLRef)mailtoURL, kLSRolesAll, NULL, &emailURL);
NSLog(@"email url: %@", [(NSURL *)emailURL autorelease]);
Make sure you add ApplicationServices.framework to your project.
 

mpemburn

macrumors member
Original poster
Jan 11, 2008
51
0
Bel Air, MD USA
Cool -- Thanks!

I just gave your code snippet a try and it returned:

email url: file://localhost/Applications/Thunderbird.app/

. . . which is spot on.

So, next I have to look into how to use this to open a new email message and hand it an attachment file.

-- Mark
 

mpemburn

macrumors member
Original poster
Jan 11, 2008
51
0
Bel Air, MD USA
Hmmm. I'm beginning to wonder if this can be done. This code:

Code:
CFURLRef mtURL = CFURLCreateWithString(kCFAllocatorDefault,CFSTR("mailto:someone@email.com"), NULL);
LSOpenCFURLRef(mtURL,nil);

. . . will open a new message with "someone@email.com" in the "TO" line. Supposedly, adding "?attachment=" to this will add an attachment but I'll be darned if I can come up with a method that will actually do that. For the most part, it does nothing.

The other possibility is to use the information returned by "LSGetApplicationForURL" to get a path to the app, craft specific command line arguments for each email client, then use NSTask to launch it. Seems like this could be involve lot of work.

-- Mark
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Adding an attachment in Mail via AppleScript (Scripting Bridge) wouldn't be that hard I imagine. Do you have to do this in the user's client? Maybe you could provide your own server to do the emailing instead.
 

mpemburn

macrumors member
Original poster
Jan 11, 2008
51
0
Bel Air, MD USA
Maybe some kind of AppleScript is my answer. I don't know a thing about AppleScript but I'll look into it.

This is strictly a local application. It's for document scanning and I want it to be able to send the scanned doc directly into email as well as into folders, etc.

One thing that indicates that this is not an easy proposition is my comparison of apps on the Mac and Windows platforms. The "ScanGear Toolbox" that my old Canon N670U uses is available for both platforms and while the Windows version lists all of my installed email clients for its 'scan to email' function, the Mac version does not. Also, one of my customers uses a Fujitsu scanner and, while it's "ScanSnap" software does offer an email option, it apparently will only work with Mac Mail (and, of course, he uses something else).

-- Mark
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
Use LSGetApplicationForURL():

Code:
NSURL *mailtoURL = [NSURL URLWithString:@"mailto:"];
CFURLRef emailURL = NULL;
LSGetApplicationForURL((CFURLRef)mailtoURL, kLSRolesAll, NULL, &emailURL);
NSLog(@"email url: %@", [(NSURL *)emailURL autorelease]);
Make sure you add ApplicationServices.framework to your project.

Nice bit of code :)
 

quinntaylor

macrumors member
Aug 13, 2008
38
0
NSWorkspace supports this

I personally find this a bit easier than using LaunchServices, and it plays nicely with ARC since there's no casting of CF types.

Code:
NSURL *emailAppURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"mailto:"]];

If you create a full mailto: URL, you can use -[NSWorkspace openURL:] to open it.
 

Mistake

macrumors newbie
Feb 28, 2013
3
0
Version of default mail client?

Use LSGetApplicationForURL():

Code:
NSURL *mailtoURL = [NSURL URLWithString:@"mailto:"];
CFURLRef emailURL = NULL;
LSGetApplicationForURL((CFURLRef)mailtoURL, kLSRolesAll, NULL, &emailURL);
NSLog(@"email url: %@", [(NSURL *)emailURL autorelease]);
Make sure you add ApplicationServices.framework to your project.

I build the code and it works good.Now i am more curious about getting the version of mail client?
How should i proceed?
Thanks
 

Mistake

macrumors newbie
Feb 28, 2013
3
0
I build the code and it works good.Now i am more curious about getting the version of mail client?
How should i proceed?
Thanks

I got it
Code:
 NSDictionary *nsAppInfo;
 NSBundle *nsAppBundle;
 NSString *nsAppPath;
 
 NSWorkspace *nsSharedWorkspace = [NSWorkspace sharedWorkspace];
 nsAppPath = [nsSharedWorkspace fullPathForApplication:appName];
 nsAppBundle = [NSBundle bundleWithPath: nsAppPath];
 nsAppInfo = [nsAppBundle infoDictionary];
 NSLog(@"%@", [nsAppInfo objectForKey:@"CFBundleShortVersionString"]);
 NSLog(@"%@", [nsAppInfo objectForKey:@"CFBundleVersion"]);

As u get the nsAppInfo dictionary you can print it and saw many system level info for use.
Thanks.
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.