0

I want to make it so that when my app's user types their email address into my UITextField, tapping the "complete purchase" button will automatically send an email populated with certain details to the address they input. This seems like it should be simple enough, however I can't seem to get it to work without popping open the Apple Mail client? Right now, I have the following code in place:

ViewController.m

- (void)sendProgram {

    if([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
        mailCont.mailComposeDelegate = self;        // Required to invoke mailComposeController when send

        [mailCont setSubject:@"Your Purchase!"];
        [mailCont setToRecipients:[NSArray arrayWithObject:@"brittany@test.ca"]];
        [mailCont setMessageBody:@"Here is the program you ordered! Please click the following link to download." isHTML:NO];

        [self presentViewController:mailCont animated:YES completion:nil];
    }
}

And technically, once the mail client pops open with all of these details filled in, all I have to do is hit the send button. However I want this information to be sent without the mail client ever opening. Is this possible?

Brittany
  • 1,359
  • 4
  • 24
  • 63
  • No it is not possible but you can send email from server side by calling API. – iVarun Sep 16 '17 at 03:37
  • The best option is that use any third party mail service for this task. There are many paid & few free third-party services available for the same. Look at these links 1. https://www.metachris.com/2016/03/free-transactional-email-services-the-best-alternatives-to-mandrill/ 2. http://blog.mashape.com/list-of-10-email-apis/ 3. https://sendgrid.com/ – Gagan_iOS Sep 16 '17 at 06:14

1 Answers1

0

You cant send mail in iOS app without opening MFMailComposeViewController. Apple does not provide any Framework for such thing. If you want to do this then you will have to use API. Server (API) will send mail to the recipients.

Ved Rauniyar
  • 1,539
  • 14
  • 21