iphone email attachment

后端 未结 4 1250
醉酒成梦
醉酒成梦 2020-12-03 04:06

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         


        
相关标签:
4条回答
  • 2020-12-03 04:30

    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];
    
    0 讨论(0)
  • 2020-12-03 04:31

    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");
     }
    
    0 讨论(0)
  • 2020-12-03 04:46

    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"];
    
    0 讨论(0)
  • 2020-12-03 04:51

    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
    
    0 讨论(0)
提交回复
热议问题