ios4.3.4:MFMailComposer不发送电子邮件,但返回MFMailComposeResultSent状态

时间:2011-11-24 12:36:04

标签: ios mfmailcomposer

我正在使用MFMailComposer。我发送电子邮件到gmail,MFMailComposer返回MFMailComposeResultSent状态。但我没有收到任何电子邮件。我用4.3.4在iphone4上测试过。我做错了什么?

MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
    mailPicker.mailComposeDelegate = self;

    // Set the subject of email
    [mailPicker setSubject:@"Subject"];
    NSString *emailBody = @"Hello from ios";

    // This is not an HTML formatted email
    [mailPicker setMessageBody:emailBody isHTML:NO];


    [self presentModalViewController:mailPicker animated:YES];

    [mailPicker release];


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    if (result == MFMailComposeResultFailed) 
 {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
 }
if (result == MFMailComposeResultSent)
 {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Message has been sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
 }
else
 {
    [self dismissModalViewControllerAnimated:YES];
 }
}
编辑:我在控制台中找到了这个:

DA|Could not open the lock file at /tmp/DAAccountsLoading.lock. We'll load the accounts anyway, but bad things may happen

EDIT2:在配备4.3.4的iPhone4上无法正常工作,但在带有4.3的ipod上工作正常。

2 个答案:

答案 0 :(得分:2)

你没有做错任何事。从Apple的网站上查看此行:

  

MFMailComposeResultSent -   电子邮件已在用户的发件箱中排队。它准备好在用户下次连接电子邮件时发送。

答案 1 :(得分:0)

不要在指定地点[mailPicker release];发布邮件选择器 ..尝试使用Autorelease方法

MFMailComposeViewController *mailPicker = [[[MFMailComposeViewController alloc] init]autorelease];

其余的都很好。