7

I am using the MFMailComposeViewController in 3.0 to send an email with attachment etc. inside my app. I would like the "To:" address to be defaulted to the default account/address on the device. How can I access this address to place it into a string for the setToRecipients?

Essentially, I'm going to let the user send an email to themselves (as the default "To") with an attachment inside the app.

driveguy
  • 793
  • 2
  • 9
  • 14

3 Answers3

5

The API doesn't expose that information publicly (for probably good reasons, such as preventing developers from harvesting iPhone users' email addresses).

You should probably go about asking for the user's email address and then saving it for future use.

Neil
  • 1,813
  • 1
  • 12
  • 20
4

It appears that the accepted answer is wrong

Getting user's default email address in Cocoa

This answer shows the code for getting the e-mail address from the address book ( listed under 'me' )

EDIT: Note the comment! OSX only not iOS :|

Community
  • 1
  • 1
P i
  • 29,020
  • 36
  • 159
  • 267
  • 4
    Just to clarify since this question is tagged for iPhone: that method appears to only work for OSX, not iOS. http://stackoverflow.com/questions/3642968/how-do-you-access-the-current-users-record-in-address-book – Erik Asmussen Jul 12 '11 at 16:31
2

You can use ABGetMe for iOS to get the user's address book card. Have a look at the source code, you will see how to retrieve all e-mail addresses for a given ABRecordRef.

0xced
  • 25,219
  • 10
  • 103
  • 255
  • 1
    "ABGetMe is not legally App Store compliant because it uses undocumented APIs which is proscribed by clause 3.3.1 of the iPhone Developer Program License Agreement. It is technically App Store compliant though as it will pass the App Store validation. Moreover, it should not crash even if the undocumented APIs change in the future." – AmineG Apr 03 '12 at 17:08
  • You can now disable private APIs in ABGetMe and it will fall back on a somewhat less effective method which does not use any private API. – 0xced Apr 23 '12 at 08:26