问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/8257171/ios4-3-4-mfmailcomposer-doesnt-send-an-email-but-return-mfmailcomposeresultse