tags:

views:

73

answers:

2

Hi. I am new to iPhone development. I am using the following code to send an email from my app in the iPhone simulator. It returns successfully but the mail is not sent.

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"My Subject"];
    [controller setMessageBody:@"Hello there." isHTML:NO]; 
    [self presentModalViewController:controller animated:YES];
    [controller release];

Then the user does the work and you get the delegate callback in time:

    - (void)mailComposeController:(MFMailComposeViewController*)controller  
              didFinishWithResult:(MFMailComposeResult)result 
                            error:(NSError*)error;
    {
      if (result == MFMailComposeResultSent) {
        NSLog(@"It's away!");
      }
      [self dismissModalViewControllerAnimated:YES];
    }

What is the problem? Thank you!

+1  A: 

As far as i know, you cannot send mail from Simulator.. The MFMailComposeViewController uses the mailbox configured in iPhone's Mail app to send the mail. The simulator does not have the Mail app.

lukya
+1  A: 

You cannot send mails through Simulator. Instead you cna install the application in device and try from there.

Simulator just displays the composer but wont allow you to send mails. Sent Successfully is just the acknowledgment that your code is fine and there is no issue that terminates it while sending.

Happy Coding...

Suriya