Can you configure email on the simulator?

Discussion in 'iOS Programming' started by Duncan C, Sep 9, 2013.

  1. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #1
    I'm working on a an app for a client that uses an MFMailComposeViewController.

    I have written code that SHOULD detect an error in sending and display a localized message to the user that includes the localizedDescription from the NSError returned to the – mailComposeController:didFinishWithResult:error: method.

    I want to test error handling throughly.

    Is it possible to set up mail on the simulator? (iOS 6.1 running under Xcode 4.6.3)

    I'd like to test various invalid cases, and would prefer not to bugger the email accounts on my other devices.

    I don't see a mail settings page in the settings panel. Oddly, I don't get an error when I try to send - it just sends and the outgoing mail seems to be dropped into the "bit bucket".
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Maybe you should use a mail framework instead?

    I've been using mailcore2 in an iOS email project I'm working on.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    I've never heard of a way to send email from the Sim.

    I probably wouldn't depend on the localizedDescription from a system provided error object. They're mostly meant for developers.
     
  4. xArtx, Sep 10, 2013
    Last edited: Sep 10, 2013

    xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #4
    It does work.
    The email is "sent" if it is sent to the stock email app, not necessarily sent over the air at that time.
    You can also check that email is enabled which means the device supports email && the user has an account set up on that device.
    In any case the composed email doesn't make it to the stock email app is an
    error, including if the user cancelled.

    You would be talking about this:
    Code:
    		case MFMailComposeResultCancelled:
                //	message.text = @"Result: canceled";
                emailstatms = 1;
    			break;
    		case MFMailComposeResultSaved:
                //	message.text = @"Result: saved";
                emailstatms = 2;
    			break;
    		case MFMailComposeResultSent:
                //	message.text = @"Result: sent";
                emailstatms = 3;
    			break;
    		case MFMailComposeResultFailed:
                //	message.text = @"Result: failed";
                emailstatms = 4;
    			break;
    		default:
                //	message.text = @"Result: not sent";
                emailstatms = 5;
    			break;
    	}
    
    See how I commented the error codes? I wanted to use my own creative descriptions:
    Code:
        if (emailstatms == 1) {
        sprintf(text, "Email Cancelled");
        }
        if (emailstatms == 2) {
        sprintf(text, "Email Saved");
        }
        if (emailstatms == 3) {
        sprintf(text, "Email Sent");
        }
        if (emailstatms == 4) {
        sprintf(text, "Email Failed");
        }
        if (emailstatms == 5) {
        sprintf(text, "Email Not Sent");
        }
    

    before sending, you can check the device has an account set up:

    Code:
    -(void)sendEmail{
        Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    	if (mailClass != nil)
    	{
        if ([mailClass canSendMail]){[self displayComposerSheet];}
    	} else {emailopen = 0;}
    }
    
     

Share This Page