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;
}
}