我在這裏發現了這個源代碼,並嘗試使用它發送郵件。 我成功地收到了'MFMailComposeResultSent'消息,但實際郵件未發送。 我不明白爲什麼不工作。 另外,我從NSData附加了一個圖像,但它不顯示在mailcomposeview中。 這段代碼有什麼問題? 實際上,我只需要用附帶圖片調用本地郵件應用程序,但我聽說沒有辦法通過附件調用本地應用程序。 請讓我知道我的代碼有什麼問題。 問題1:不從mailcomposeview發送郵件, 問題2:不顯示附加圖像。 最佳:使用附加圖像運行本機郵件應用程序。 我會很高興地等待你的答案。謝謝。爲什麼我的發送郵件不能從MFMailComposeViewController工作?
-(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;
}
}
你通過模擬器或設備上發送? – shabbirv 2012-07-10 01:21:56
我通過設備測試過。 – user1471568 2012-07-10 01:53:24
您的設備是否在網絡上?我想當你收到MFMailComposeResultSent時,它實際上意味着它已經成功地告訴郵件應用發送郵件,但如果你沒有網絡,它可能實際上排隊等待發送和等待。 – Stew 2012-07-10 04:11:22