Aravindhan
Aravindhan

Reputation: 15628

Problem in sending a mail from simulator

I am trying to create a small email apps. Everything works correctly but the email is not sending. Whether i have do something for this. I am learning by myself. so i lack something. here is my code..

-(void)viewDidLoad
{
    UIButton *but01 = [UIButton buttonWithType:UIButtonTypeRoundedRect];                    //Button I
    but01.frame = CGRectMake(240,10, 70, 50);
    [but01 setTitle:@"ADD" forState:UIControlStateNormal];
    [but01 addTarget:self action:@selector(sendMail) 
    forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:but01];


}

- (IBAction)sendMail {
    if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *mfViewController = [[MFMailComposeViewController alloc] init];
        mfViewController.mailComposeDelegate = self;

        [self presentModalViewController:mfViewController animated:YES];
        [mfViewController release];
    }else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Your phone is not currently configured to send mail." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];

        [alert show];
        [alert release];
    }
}


#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate Methods

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];

    switch (result) {
        case MFMailComposeResultCancelled:
            alert.message = @"Message Canceled";
            break;
        case MFMailComposeResultSaved:
            alert.message = @"Message Saved";
            break;
        case MFMailComposeResultSent:
            alert.message = @"Message Sent";
            break;
        case MFMailComposeResultFailed:
            alert.message = @"Message Failed";
            break;
        default:
            alert.message = @"Message Not Sent";
        break;  }
    [self dismissModalViewControllerAnimated:YES];

    [alert show];
    [alert release];
}

For this i am getting this message in the console. What can i do now?

29/04/11 4:03:04 PM SpringBoard[3115]   Reloading application state for 'com.yourcompany.Sendmail' as its modification date has changed    
29/04/11 4:03:04 PM com.apple.launchd.peruser.501[95]   (UIKitApplication:com.yourcompany.Sendmail[0x38e1][3206]) Exited: Killed    
29/04/11 4:03:04 PM SpringBoard[3115]   Reloading and rendering all application icons.    
29/04/11 4:03:04 PM SpringBoard[3115]   Application 'Sendmail' exited abnormally with signal 9: Killed

Upvotes: 1

Views: 394

Answers (1)

saadnib
saadnib

Reputation: 11145

MFMailCompose doesn't work in simulator, check it on device

Upvotes: 2

Related Questions