1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| //1-头部 @interface ILShareViewController ()<MFMailComposeViewControllerDelegate> @end //2-分享 // 不能发邮件处理 if (![MFMailComposeViewController canSendMail]) return; MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
// 设置邮件主题 [vc setSubject:@"会议"]; // 设置邮件内容 [vc setMessageBody:@"今天下午开会吧" isHTML:NO]; // 设置收件人列表 [vc setToRecipients:@[@"643055866@qq.com"]]; // 设置抄送人列表 [vc setCcRecipients:@[@"1234@qq.com"]]; // 设置密送人列表 [vc setBccRecipients:@[@"56789@qq.com"]];
// 添加附件(一张图片) UIImage *image = [UIImage imageNamed:@"阿狸头像"]; NSData *data = UIImagePNGRepresentation(image); [vc addAttachmentData:data mimeType:@"image/png" fileName:@"阿狸头像.png"]; // 设置代理 vc.mailComposeDelegate = self; // 显示控制器 [self presentViewController:vc animated:YES completion:nil]; //3-代理 - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { // 关闭邮件界面 [controller dismissViewControllerAnimated:YES completion:nil]; if (result == MFMailComposeResultCancelled) { NSLog(@"取消发送"); } else if (result == MFMailComposeResultSent) { NSLog(@"已经发出"); } else { NSLog(@"发送失败"); } }
|