Nasir Khan Nasir Khan - 1 year ago 103
iOS Question

Sent email from IOS Simulator but not receiving in mailbox

Here is my code:

- (void)sendMail:(id)sender{
// Email Subject
NSString *emailTitle = @"Test Email";
// Email Content
NSString *messageBody = @"Learning iOS Programming"; // Change the message body to HTML
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@""];

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:YES];
[mc setToRecipients:toRecipents];

// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
switch (result)
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
case MFMailComposeResultSent:
NSLog(@"Mail sent");
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);

// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];

Answer Source

You can't send mail from Simulator. You need to setup Mail Account from Settings to be able to do that, which is not available in Simulators Settings, its available only in Devices.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download