0

I want to send multiple attachment files in single mail in iOS programatically. I have tried the following so far:

 // I give the file from array 
NSString *str_mail = [readingEmfReading objectAtIndex:0];
//  here I can encode the file
NSData *myData = [str_mail dataUsingEncoding:NSUTF8StringEncoding]
//here I can attach the file with extance of .csv
[controller addAttachmentData:myData mimeType:@".cvs" fileName:retriveEmail]  
//here I can set the body for mail 
[controller setMessageBody:@"file" isHTML:NO];
//here code for sent mail
if (controller) [self presentViewController:controller animated:YES completion:nil];

By using this code, I can only send one attachment. I want to send multiple files however. How can I achieve this?

2
  • Below is another stack over flow link stackoverflow.com/questions/5107926/… This might help you Commented May 9, 2013 at 11:27
  • call the method –addAttachmentData:mimeType:fileName: any times you'd like to add an attachment, it is an kind of add not a kind of set method (see the prefix)... the difference is obvious, but the documentation could also help, if you are unsure. Commented May 9, 2013 at 11:55

2 Answers 2

1

you add many time addAttachmentData and add muliple file

try this code :- add the this line

NSString *str_mail = [readingEmfReading objectAtIndex:0];
//  here i can encoded the file
NSData *myData = [str_mail dataUsingEncoding:NSUTF8StringEncoding]

NSData *myData1 = [str_mail dataUsingEncoding:NSUTF8StringEncoding]
//here i can attach the file with extance of .csv
[controller addAttachmentData:myData mimeType:@".cvs" fileName:retriveEmail]  
//here i can set the body for mail 


// For second file 

NSData *myData1 = [str_mail dataUsingEncoding:NSUTF8StringEncoding]

[controller addAttachmentData:myData1 mimeType:@".cvs" fileName:retriveEmail] 

[controller setMessageBody:@"file" isHTML:NO];
//here code for sent mail
if (controller) [self presentViewController:controller animated:YES completion:nil];
Sign up to request clarification or add additional context in comments.

Comments

0
if([MFMailComposeViewController canSendMail])
        {
            [mailController setMailComposeDelegate:self];
            NSString* message=@"";
            NSString *filePath;
            for (int i=0; i<filesarray.count; i++)
            {
                if (i==filesarray.count-1)
                {
                    message=[message stringByAppendingFormat:@"%@ ",[filesarray objectAtIndex:i]];
                }
                else if (i==filesarray.count-2)
                {
                    message=[message stringByAppendingFormat:@"%@ and ",[filesarray objectAtIndex:i]];
                }
                else
                    message=[message stringByAppendingFormat:@"%@, ",[filesarray objectAtIndex:i]];
                NSString *datPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
                datPath = [datPath stringByAppendingFormat:@"/%@.csv",[filesarray objectAtIndex:i]];
                filePath = datPath;
                [mailController addAttachmentData:[NSData dataWithContentsOfFile:filePath] mimeType:@"text/csv" fileName:[NSString stringWithFormat:@"%@.csv",[filesarray objectAtIndex:i]]];
            }
            [mailController setSubject:message];
            [mailController setMessageBody:@"" isHTML:NO];
            [self presentModalViewController:mailController animated:YES];
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.