import <MessageUI/MFMailComposeViewController.h>
MFMailComposeViewControllerDelegate
-
(void)sendEmail {
Class mainlClass=NSClassFromString(@"MFMailComposeViewController");
if (!mainlClass) {
[self showMessage:@"当前系统版本不支持应用内发送邮件功能"];
return;
}if (![mainlClass canSendMail]) {
[self showMessage:@"你还没有设置邮件账户"];return;
}
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate=self;//设置主题
[mailPicker setSubject:@"Redo.Me 意见反馈"];//添加收件人
NSArray *toRecipients=[NSArray arrayWithObject:@"chjwrr@163.com"];
[mailPicker setToRecipients:toRecipients];
//添加抄送
NSArray *ccRecipients=[NSArray arrayWithObject:@""];
[mailPicker setCcRecipients:ccRecipients];
//添加密送
NSArray *bccRecipients=[NSArray arrayWithObject:@""];
[mailPicker setBccRecipients:bccRecipients];
//添加一张图片
UIImage *image=[UIImage imageNamed:@""];
NSData *imageData=UIImagePNGRepresentation(image);
[mailPicker addAttachmentData:imageData mimeType:@"png" fileName:@"icon.png"];
//添加一个附件
NSString *filePath=@"附件路径";
NSData *fileData=[NSData dataWithContentsOfFile:filePath];
[mailPicker addAttachmentData:fileData mimeType:@"" fileName:@"附件名字+后缀名"];
NSString *emailBody=@"<font color='red'> 一张照片,一幅场景<br />一句情话,一段回忆<br />一篇文章,一个曾经<br />既然时间无法Undo<br />那么就 Redo.Me </font>";
NSString *msg=[NSString stringWithFormat:@"<br />手机型号:%@<br />系统版本:%.2f<br />应用版本:%@",[NSString phoneName],kAPP_System_Version,kAPP_Bundle_Version];
[mailPicker setMessageBody:[NSString stringWithFormat:@"%@\n%@",emailBody,msg] isHTML:YES];
[self presentViewController:mailPicker animated:YES completion:^{
}];
}
pragma mark - MFMailComposeViewControllerDelegate
-
(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];switch (result) {
case MFMailComposeResultSent:{
[self showMessage:@"邮件已发送"];} break; case MFMailComposeResultCancelled:{ [self showMessage:@"邮件已取消"]; } break; case MFMailComposeResultFailed:{ [self showMessage:@"邮件发送失败,请重试"]; } break; case MFMailComposeResultSaved:{ [self showMessage:@"邮件保存成功"]; } break; default: break;
}
}