Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ZipArchive Zip file in iphone mail attachment?

Tags:

iphone

is it possible to send a zip Archive file inside an email attachment using the mail api?

like image 583
Silent Avatar asked Sep 11 '25 02:09

Silent


2 Answers

Try This .. This one worked for me

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0]; 

NSString *WritableDBPath= [documentsDirectory stringByAppendingPathComponent:kFilename]; 

NSData *data = [NSData dataWithContentsOfFile:WritableDBPath];

[picker addAttachmentData:data mimeType:@"application/zip" fileName:@"/abc.zip"];
[picker setSubject:@"Database"];

[picker setMessageBody:@"Database testing" isHTML:NO];

[self presentModalViewController:picker animated:YES];
like image 61
Ravi Chokshi Avatar answered Sep 13 '25 17:09

Ravi Chokshi


Yes it is possible.

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *WritableDBPath= [documentsDirectory stringByAppendingPathComponent:kFilename];
    NSData *data = [NSData dataWithContentsOfMappedFile:WritableDBPath];

    [picker addAttachmentData:data mimeType:@"text/richtext" fileName:@"/abc.zip"];
    [picker setSubject:@"Database"];

    [picker setMessageBody:@"Database testing" isHTML:YES];

    [self presentModalViewController:picker animated:YES];

You can choose the filepath, filename as per your choice. Please verify the mime-type if its not work.

:)

like image 34
iphonedev23 Avatar answered Sep 13 '25 17:09

iphonedev23