9

I used the MessageUI framework to send the mail with attachment from my application. But i got the following error,

2009-09-07 19:52:23.483 emailTest[11711:5b17]
 Error loading /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): Library not loaded: /System/Library/PrivateFrameworks/MobileWirelessSync.framework/MobileWirelessSync

 Referenced from: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator

      Reason: image not found

2009-09-07 19:52:23.489 emailTest[11711:5b17] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
[Switching to process 11711 local thread 0xf03]

my code is,

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[picker setSubject:@"This is iPhone email   attachment test"];

UIImage *sampleImg = [UIImage imageNamed:@"iPhone.jpg"];
NSData *imageData = UIImageJPEGRepresentation(sampleImg, 1);
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"iPhone.jpg"];


NSString *emailBody = @"I am sending the image attachment with iPhone email service";
[picker setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:picker animated:YES];
[picker release];

please help me.

DShah
  • 9,510
  • 10
  • 66
  • 123
SST
  • 2,042
  • 5
  • 26
  • 42
  • Be more specific - what code are you running to create the attachment? To detach the message? How exactly are you "using the MessageUI framework"? – Tim Sep 07 '09 at 14:59
  • please take a look at the code. – SST Sep 07 '09 at 15:06
  • hi, did you get your code worked. I too got the same message while touched the send button in email. But, I am not adding any attachments with the mail. I could not dismiss the mail controller when I touched the cancel button . I am adding the mail controller to cocos2d layer. Any help please. Thank You. – srikanth rongali May 12 '10 at 06:49

4 Answers4

16

You do not have to type extension in your filename. like "iphone.jpg" is not working. just write "iphone" in filename because you already define mimeType. And also you have to define path for resource.

Below is the sample code to attach "rainy.png" file with mail.

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Hello"];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];  
[picker setBccRecipients:bccRecipients];

// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"It is raining";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];
Jay Vachhani
  • 694
  • 5
  • 14
0

Add following method to dismiss the MFMailComposeViewController:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:   (MFailComposeResult)result error:(NSError*)error

 {
 // NEVER REACHES THIS PLACE
 [self dismissModalViewControllerAnimated:YES];

 NSLog (@"mail finished");
 }
user1119116
  • 747
  • 1
  • 7
  • 16
  • Good point, but that's probably not the problem here... btw, should be `MFMailComposeResult` instead of `MFailComposeResult`. – newenglander Oct 29 '12 at 12:10
0

This error seems to be related to the running mail int he simulator and not to your code. Even stock Apple's sample MailComposer reports identical error in the simulator:

2009-11-12 20:30:39.270 MailComposer[7426:4f1f] Error loading /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): Library not loaded: /System/Library/PrivateFrameworks/MobileWirelessSync.framework/MobileWirelessSync
  Referenced from: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator
  Reason: image not found
2009-11-12 20:30:39.271 MailComposer[7426:4f1f] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
FreeAsInBeer
  • 12,837
  • 5
  • 46
  • 79
leon
  • 1,382
  • 1
  • 15
  • 25
  • Hi, I am getting the same in the log. When I touched the close or send button in mail controller. I am adding the mail controller to cocos2d layer. And I do not get "running mail int he simulator and not to your code". What is it ? can we change it ? Thank you. – srikanth rongali May 12 '10 at 06:29
0

use this for attach image in a mail, tested in ios 4,5,6

    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    UIImage *myImage = [UIImage imageNamed:@"image.png"];
    NSData *imageData = UIImagePNGRepresentation(myImage);
    [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"image"];
busta117
  • 476
  • 4
  • 7