3

HI, I am looking for help, I am new to cocoa and iphone programming

Is there a way to send an email, using standard account configured on the device WITHOUT opening a compose UI?

I want to write an app to send me email reminders.

you have a text area where you type something, when you hit button send at the titlebar it sends contents of text area to my email, that's it

I have done the text area and button thing, but it opens me a compose window, when I use MFMailComposeViewController...

or maybe using compose window, but hide certain fields, such as to, cc, bcc...

all of articles I've found on the internet are either outdated or about MFMailComposeViewController...

looking forward to hearing a replay from you

Thanks...

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
Matt Harasymczuk
  • 1,728
  • 2
  • 21
  • 29

2 Answers2

10

It is possible to use MFMailComposeViewController without user interaction. This technique obviously relies on undocumented APIs, so it may break anytime. Also, it wouldn't be a good idea to submit an app doing this to the App Store…

- (void) sendStealthEmail
{
    MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
    mailComposeViewController.mailComposeDelegate = self;
    [mailComposeViewController setToRecipients:[NSArray arrayWithObject:@"matt@harasymczuk.pl"]];
    [mailComposeViewController setSubject:@"Stealth email"];
    [mailComposeViewController setMessageBody:@"Pwned" isHTML:NO];
    [mailComposeViewController view];
}

- (void) mailComposeController:(MFMailComposeViewController*)mailComposeViewController bodyFinishedLoadingWithResult:(NSInteger)result error:(NSError*)error
{
    @try
    {
        id mailComposeController = [mailComposeViewController valueForKeyPath:@"internal.mailComposeController"];
        id sendButtonItem = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.sendButtonItem"];
        [mailComposeController performSelector:@selector(send:) withObject:sendButtonItem];
    }
    @catch (NSException *e) {}
    [mailComposeViewController release];
}
0xced
  • 25,219
  • 10
  • 103
  • 255
  • @Oxced it is not working with the latest iOS 6 can you suggest any solution? – Marine Feb 15 '13 at 13:08
  • Ole Begemann has an excellent explanation of why this stopped working on iOS 6: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/ There is nothing we can do about it and that’s actually a good thing! – 0xced Feb 15 '13 at 21:25
  • @0xced. Would apple approve this? – Gajendra K Chauhan Aug 07 '13 at 11:36
  • No, Apple would not not approve this. – 0xced Aug 09 '13 at 19:22
  • This API is documented and supported by Apple now: https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/index.html – Oren Dec 16 '14 at 22:36
  • The `MFMailComposeViewController` class has not changed since iOS 3.0 and sending stealth e-mails is not supported. – 0xced Dec 17 '14 at 13:28
2

MFMailComposeViewController is the class that is provided by Apple to send mails.

If you don't want to use the composer you have to write your own smtp client. (It could be php, .net, java or any other technolgy). You can also try skpsmtpmessage

iHS
  • 5,372
  • 4
  • 31
  • 49
  • Yes this is working fine...and I need from my application it needs to fetch the present using mail from MAIL application ...Then i want to send a mail from that mail Id. – sairam Apr 20 '14 at 05:23