How to send mail from iphone app without showing MFMailComposeViewController?

Yuvaraj.M picture Yuvaraj.M · Feb 24, 2012 · Viewed 12.4k times · Source

I want to send mail from my custom iPhone app. I have used MFMailComposeViewController to send mail from my iphone in my previous app. Now, i don't want to show the MFMailComposeViewController to the user, if they click Send Mail button the mail automatically send to the recipient mail address. How can i do this? Can you please help me on this? Thanks in advance.

I have used below code to show the MFMailComposeViewController,

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"Details"];
[controller setMessageBody:@"Hi" isHTML:NO];
[controller setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]];
[self presentModalViewController:controller animated:YES];
[controller release];

Answer

Srikar Appalaraju picture Srikar Appalaraju · Feb 24, 2012

Sending emails programmatically, without user intervention, from an iphone application, cannot be implemented using any of the Apple frameworks. It could be possible in a jailbroken phone but then it would never see the inside of App Store.

If you want control of email sending, then a better way would be to set up a web service (at your server end) you can post to using an HTTP request. If you are posting to only one address this can work very well, although you may want to get the user to input their return mail address.

Otherwise only the standard dialog is available (this relies on using whatever account they've setup on the device).