简体   繁体   English

如何在 OS X Lion 上获取用户邮件地址?

[英]How to get users mail addresses on OS X Lion?

I was getting the users mail addresses from Libraray/Preferences/com.apple.mail.plist.我从 Libraray/Preferences/com.apple.mail.plist 获取用户邮件地址。 They are not there any more in Lion:P Do I have to use scripting bridge? Lion:P 中不再有它们了,我必须使用脚本桥吗? Any hints?有什么提示吗? Thanks谢谢

I would get them right out of Address Book.我会把它们从地址簿中取出。 That should work regardless of what email app is being used.无论使用什么 email 应用程序,这都应该有效。

// Find 'me' card in address book.
ABPerson* meCard = [[ABAddressBook sharedAddressBook] me];
if( meCard == nil ) {
    NSLog( @"Could not find me!" );
    return;
}

// Get my email addresses.
ABMultiValue* anEmailList = [meCard valueForProperty:kABEmailProperty];
if( anEmailList == nil ) {
    NSLog( @"I have no email!" );
    return;
}

// Output them.
for( NSUInteger index = 0; index < [anEmailList count]; index++ ) {
    NSString* aLabel = [anEmailList labelAtIndex:index];
    NSString* aValue = [anEmailList valueAtIndex:index];
    NSLog( @"%@: %@", aLabel, aValue );
}

Mail in Lion stores the equivalent in ~/Library/Mail/V2/MailData/Accounts.plist . Lion 中的 Mail 将等价物存储在~/Library/Mail/V2/MailData/Accounts.plist中。 Note however that you are assuming that the user uses the Apple Mail program, unless that's what you really need you may want to have alternative methods for getting the address.但是请注意,您假设用户使用 Apple Mail 程序,除非这是您真正需要的,否则您可能希望有其他方法来获取地址。 You may for instance depending on how the system has been set up use the CSIdentity APIs, such as CSIdentityGetEmailAddress().例如,您可以根据系统的设置方式使用 CSIdentity API,例如 CSIdentityGetEmailAddress()。

Apple script will get the job done.苹果脚本将完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM