如何在从iphone应用程序发送电子邮件时在电子邮件中添加cc

时间:2013-05-25 09:49:33

标签: iphone cocoa-touch email

我正在从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:PEISupportServices@zoetis.com<br>Fax:800-741-1310<body></html>";



[picker setMessageBody:emailBody isHTML:YES];





[self.navigationController presentViewController:picker animated:YES completion:nil];

3 个答案:

答案 0 :(得分:0)

MFMailComposeViewController有一个setCcRecipients:方法。你可以这样使用它:

[picker setCcRecipients:[NSArray arrayWithObject:@"someone@example.com"]];

答案 1 :(得分:0)

    NSString *subject = @"";
    NSString *body = @"";
    NSString *address = @"to@gmail.com";
    NSString *cc = @"cc@gmail.com";
    NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
    NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [[UIApplication sharedApplication] openURL:url];

答案 2 :(得分:0)

[mailComposeViewController setToRecipients:@[@"ibanking@com"]];

[mailComposeViewController setCcRecipients:@[@"ccs.cmc@com"]];