by 伍雪穎
第一種:
NSString *myEmail = @"[email protected]"; NSString *toemail = @"[email protected]"; NSString *emailDetail = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=Feedback!&body=Dear:",toemail,myEmail]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailDetail]];
- (void)displayMailPicker { MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init]; mailPicker.mailComposeDelegate = self; [mailPicker setSubject: @"Feedback!"]; NSArray *toRecipients = [NSArray arrayWithObject: @"[email protected]"]; [mailPicker setToRecipients: toRecipients]; NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil]; [mailPicker setCcRecipients:ccRecipients]; // add a picture UIImage *addPic = [UIImage imageNamed: @"[email protected]"]; NSData *imageData = UIImagePNGRepresentation(addPic); [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"]; NSString *emailBody = @"Dear:"; [mailPicker setMessageBody:emailBody isHTML:YES]; [self presentViewController:mailPicker animated:YES completion:nil]; } - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { [self dismissViewControllerAnimated:YES completion:nil]; }