开发者

sending doc file as an attachment on iPad

I wa开发者_如何学Cnt to send .doc file as an email attachment from my app programmatically.


Use -[MFMailComposeViewController addAttachmentData:] with a mimeType of "application/msword". For example:

- (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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜