jonty
jonty

Reputation: 23

How to attach m4v video in email with MFMailcomposer in iphone

I am using this code  but it is not sending mail with video here is my code :

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];  
        controller.mailComposeDelegate = self;  
        [controller setSubject:@"My Subject"];  
        [controller setMessageBody:@"" isHTML:NO]; if (controller) [self presentModalViewController:controller animated:YES];  
        [controller release];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:titleString];

        NSLog(@"datapath=%@",dataPath);

        NSURL *url=[[NSURL alloc] initFileURLWithPath:dataPath];

        NSLog(@"url..%@",url);

        NSData *data=[[NSData alloc]initWithContentsOfURL:url ];

  [controller addAttachmentData:data mimeType:@"video/quicktime" fileName:titleString];

plzz help me

Upvotes: 0

Views: 986

Answers (1)

freelancer
freelancer

Reputation: 1658

here is code

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

 [picker setSubject:@"Subject Name"];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:emailsenderaddress]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"", @"", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@""]; 

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

// Attach an file to the email


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

NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *saveDirectory = [documentPath objectAtIndex:0];

NSString *saveFileName = [NSString stringWithFormat:@"fileNmae%@.m4v",[invoiceidarray objectAtIndex:OptionView.tag]];

NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];

NSData *pdfData = [NSData dataWithContentsOfFile:finalPath];
[picker addAttachmentData:pdfData mimeType:@"application/m4v" fileName:saveFileName];
[self presentModalViewController:picker animated:YES];
[picker release];

}

Upvotes: 1

Related Questions