0

I am using MFMailComposer. I send email to gmail, MFMailComposer returns MFMailComposeResultSent status. But I don't received any email. I tested on iphone4 with 4.3.4. What I do wrong?

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];
 }
}

EDIT: I found this in console :

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

EDIT2: On iPhone4 with 4.3.4 doesn't work, but on ipod with 4.3 works OK.

Voloda2
  • 12,359
  • 18
  • 80
  • 130

2 Answers2

2

You do nothing wrong. Check this line from Apple's website:

MFMailComposeResultSent – The email message was queued in the user’s outbox. It is ready to send the next time the user connects to email.

Emil
  • 7,220
  • 17
  • 76
  • 135
0

Dont release the mail picker at the specified spot [mailPicker release]; .. try using the Autorelease method for the

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

the rest is good.

medampudi
  • 399
  • 3
  • 15
  • It does not matter. `mailPicker` will retained when presenting as modal – beryllium Nov 24 '11 at 12:45
  • @beryllium i was having the same problem so i solved it using this method so can you please suggest something better... i am also willing to know more about it to implement in my applicaitons. – medampudi Nov 24 '11 at 12:57