Swastik
Swastik

Reputation: 2425

sending doc file as an attachment on iPad

I want to send .doc file as an email attachment from my app programmatically.

Upvotes: 1

Views: 2320

Answers (1)

Stephen Poletto
Stephen Poletto

Reputation: 3655

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:@"[email protected]"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [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];
}

Upvotes: 6

Related Questions