I found this source code from here and tried sending mail using it. I successfully got the 'MFMailComposeResultSent' Message, but actual mail is not sent. I don't understand why is not working. Also, I attached an image from NSData, but it doesn't display in mailcomposeview. What is the wrong with this code? Actually, I only need calling native mail app with an attachement image, but I heard there is no way calling the native app with attachement. Please let me know what is wrong with my code. Problem 1: doesn't send a mail from mailcomposeview, Problem 2: doesn't display attached image. Best : running native mail app with attached image. I'll be happily waiting your answers. Thx.
-(void) sendMail
{
NSLog(@"Mail");
MFMailComposeViewController *mfMailView = [[MFMailComposeViewController alloc]init];
NSData *imgData = UIImagePNGRepresentation(imgPreview.image);
mfMailView.mailComposeDelegate = self;
[mfMailView addAttachmentData:imgData mimeType:@"image/png" fileName:@"Me.png"];
//also tried this
//[mfMailView addAttachmentData:imgData mimeType:@"image/png" fileName:@"Me"];
[mfMailView setSubject:@"TE~st"];
[mfMailView setMessageBody:@"Download Me~!" isHTML:YES];
[self presentModalViewController:mfMailView animated:YES];
}
-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@"cancel?");
break;
case MFMailComposeResultSaved:
NSLog(@"saved?");
break;
case MFMailComposeResultSent:
NSLog(@"Sent succed");
[controller dismissModalViewControllerAnimated:YES];
break;
case MFMailComposeResultFailed:
NSLog(@"sent failue");
NSLog(@"%@",error);
break;
default:
break;
}
}
You can take a reference from this link.