在iPad上将doc文件作为附件发送

时间:2011-04-01 05:47:39

标签: objective-c ipad mfmailcomposeviewcontroller

我想以编程方式从我的应用程序发送.doc文件作为电子邮件附件。

1 个答案:

答案 0 :(得分:6)

使用 - [MFMailComposeViewController addAttachmentData:],其mimeType为“application / msword”。例如:

- (void)displayComposerSheet {
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"I'm attaching a word document!"];

    // 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 a doc to the email
    NSString *path = [[NSBundle mainBundle] pathForResource:@"MyDocument" ofType:@"doc"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"application/msword" fileName:@"MyDocument"];

    // Fill out the email body text
    NSString *emailBody = @"Please see the attached document.";
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}
相关问题