2010-08-03 44 views
0

我想使用MFMailComposeViewController發送郵件。一切工作,除了郵件不發送,我總是得到MFMailComposeResultFailed。MFMailComposeViewController不發送郵件

任何指針?我不使用模擬器,併發送郵件從我的設備工作。我確實有一個連接(通過Reachability進行測試),[MFMailComposeViewController canSendMail]返回YES。

項目,沒有崩潰沒有編譯器警告......

回答

2

這是IOS4中的一個錯誤。

我的手機上同時擁有Exchange郵件帳戶和舊的非活動IMAP帳戶。顯然,這導致了iOS4的問題。郵件實際上被卡在發件箱中。一旦我刪除不活動的IMAP帳戶,一切都按預期工作。

+0

看起來像4.1中仍然存在的錯誤。還不確定4.2。 – 2010-11-05 14:06:42

0

這很難說沒有看到一個代碼片段,但您應檢查以下內容:

1)您已正確設置MFMailComposeViewController's委託並實施其代表方法;

2)你有設置使用setSubject:

3)已設置使用setMessageBody:isHTML:

消息體和任選地設置一個附加使用郵件主體addAttachmentData:mimeType:fileName:

4)您已呈現給用戶您的郵件撰寫視圖控制器使用類似

[self presentModalViewController:mcvc animated:YES]; 

H這有助於。

+1

是啊,我已經全部正確。原來,這是一個操作系統中的錯誤。請參閱下面的答案。 無論如何謝謝:) – 2010-08-04 07:11:02

1

有些讀者可能會面臨這樣的問題:

確保您實現<MFMailComposeViewControllerDelegate>協議

下面的代碼:

// in TestViewController.h 
@interface TestViewController : UIViewController<MFMailComposeViewControllerDelegate> 
@end 

// in TestViewController.m 
@interface TestViewController() 
@end 

@implementation 
- (void) compose { 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Hello there"]; 

    [picker setToRecipients:@[]]; 

    // Fill out the email body text 
    NSString *emailBody = @"Hello, sending a message from my app"; 

    [picker setMessageBody:emailBody isHTML:NO]; 

    // use this function. presentModalViewController:... is deprecated 
    [self presentViewController:picker animated:YES completion:nil]; 
} 

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
@end 
相關問題