我从这里找到了这份源代码,并尝试使用它发送邮件。虽然成功得到了“MFMailComposeResultSent”消息,但实际上并没有发送邮件。我不明白为什么会出现这种情况。此外,虽然我已经将图像转换成NSData并附加到了邮件中,但在邮件撰写视图中却没有显示出来。这段代码存在什么问题呢?实际上,我只需要调用本地的邮件应用程序并在其中附加一张图片,但我听说没有办法在调用本地应用程序时附加文件。请告诉我我的代码有什么问题。问题1:无法从邮件撰写视图中发送邮件,问题2:无法显示附加的图片。最好的解决方法是,在本地邮件应用程序中运行附带图片的操作。期待您的回答,谢谢。
-(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;
}
}