iPhone send email not using MessageUI

半腔热情 提交于 2019-11-27 20:20: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];
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!