I want to know if it\'s possible to send email through iPhone simulator. I have seen the tutorial for sending an email through iphone as below:
http://www.edumobile.org/
You can use the MessageUI framework on the simulator to compose and 'send' messages, but I don't believe there's a way to actually send the message. Once the user hits the Send button in the message composition view, though, your code doesn't have any role in sending the message. So the simulator does enough that you can develop and test your app.
As for whether it's necessary to have a real device, I'd say that at some point you need to test on one or more devices no matter what. The simulator is a great tool, but after a certain point it's no substitute for running your app on the real thing.
You have to rely on the iOS that the MFMailComposeResult
that is handed back in mailComposeController:didFinishWithResult:error:
is correct. The simulator fakes that result; no actual mail is sent although it says MFMailComposeResultSent
.
The tutorial mentioned misses an important point: The first thing you should do before using MFMailComposeViewController
is to check [MFMailComposeViewController canSendMail]
. That will return NO
, if the user hasn't configured mail on their device. If you must support an iOS version prior to 3.0 the correct way is to check if the class MFMailComposeViewController
exists:
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
The canSendMail-issue can only be tested on a real device though. It will crash if you don't check canSendMail and the user has no mail account configured.
As per the discussion on apple forum, to test the functionality we really need a device, simulator does not support this functionality.
A part from discussion:
sptrakesh Chicago Re: IOS SIMULATOR
MAIL APP Mar 26, 2012 7:09 AM (in response to davemac75)
The mail application is not available on the simulator. You will need to test your application on a device to test that part.
Yes it is necessary if you want to actually send the email.
in most of the cases there is no need for you to worry as the mail is going to be sent by apple app, so you will need only to verify that your app is responding and launches the mail composer. The only thing i can think as problematic is if you want to make sure that attachments and images are sent properly. In this case you can send a beta to someone with iphone and ask him to check it for you.
important having a device is critic to developing, your simulator does not behave exactly as the device. he is a forgiver and in my experience i always had issues with the device that weren't with the simulator.