我正在从iphone应用程序发送电子邮件它工作正常我想在电子邮件中添加cc任何想法如何做到这一点。我正在使用以下代码,请你帮忙如何在这里添加CC。
谢谢。
初始化控制器以发送电子邮件
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString*giveFileName=@"CPAC_Contract_Equine";
NSString *fileName;
//fileName = [[NSString alloc]initWithFormat:@"%@.pdf",giveFileName];
fileName = [[NSString alloc]initWithFormat:@"%@",giveFileName];
NSString*myFileName=@"W9.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
NSMutableData *myPdfData = [NSMutableData dataWithContentsOfFile:pdfFileName];
NSString *pathJam = [[NSBundle mainBundle] pathForResource:@"W9" ofType:@"pdf"];
NSData *myDataJam = [NSData dataWithContentsOfFile: pathJam];
NSArray * toRecipients = [NSArray arrayWithObject:@""];
[picker setToRecipients:toRecipients];
[picker setSubject:@"CPAC Contract for Equine-Sam Veterinarian"];
[picker addAttachmentData:myPdfData mimeType:@"application/pdf" fileName:giveFileName];
NSString * emailBody =@"<html><body>Thank you for your participation in Consulting<br>Practitioner and Client Program.</br><br>Attached is the copy of your signed contract for your records<p>Please email or fax your completed W-9 form to<br>our PEI Support Team<br>Email:[email protected]<br>Fax:800-741-1310<body></html>";
[picker setMessageBody:emailBody isHTML:YES];
[self.navigationController presentViewController:picker animated:YES completion:nil];
MFMailComposeViewController有一个setCcRecipients:
方法。你会像这样使用它:
[picker setCcRecipients:[NSArray arrayWithObject:@"[email protected]"]];
NSString *subject = @"";
NSString *body = @"";
NSString *address = @"[email protected]";
NSString *cc = @"[email protected]";
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
[mailComposeViewController setToRecipients:@[@"ibanking@com"]];
[mailComposeViewController setCcRecipients:@[@"ccs.cmc@com"]];