0

I'm building an internal app. I want to be able to press a button, and have the app automatically send a predefined email message to a specified email address, without the user knowing. I have access to a web-server, but I'm just not quite sure on what the best way to go about doing this is.

I'm using storyboard in xcode, this is a singleview application for the ipad.

Any suggestions are greatly appreciated.

Ben T.
  • 39
  • 1
  • 5

3 Answers3

1

If you want to use the user's mail account that they have set up in the mail.app - you can't do that without the MFMailComposeViewController.

Solutions are:

  • Use some Framework or roll your own mail solution that you or the user fills with their respective mail acc data and then send mails.

or

  • Write a little PHP/Ruby/Java/... script that sends a mail which you can trigger via web request (i.e. REST).
pkluz
  • 4,871
  • 4
  • 26
  • 40
  • I don't want to use the users mail account, I want to just use one that I setup on the web-server to send the messages. Would a php script be the right route? – Ben T. Aug 15 '12 at 16:37
1

SKPSMTPMessage works well for sending emails without the need for a UI.

(Make sure you add a reference to the CFNetwork.framework in your project.)

Ian L
  • 5,553
  • 1
  • 22
  • 37
1

You can create a PHP script that can do this (code below). Use a library such as ASIHTTPRequest to post the user's email address to the script and then the script will automatically send the message.

<?php

    $to = $_POST["email"]; //this is the user's address; you can replace $_POST["email"] with "user@example.com" to try it out
    $subject = "Subject";
    $body = "Message";
    $headers = "From: Name <noreply@example.com>\r\n" . "X-Mailer: php";

    if (mail($to, $subject, $body, $headers)) {

        //sent

    }

?>
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
  • Can I have this script locally on iPhone? How do I invoke it? – Paresh Masani Aug 28 '13 at 23:14
  • @AppleDeveloper No, PHP does not run on an iPhone. If you don't have a server to run this script, then your only other option is to connect to a mail relay and send the message with the iPhone. This is insecure and a bad idea. – Jack Humphries Aug 28 '13 at 23:55
  • thanks for clarifying this. I have used SMTP approach. It works great - http://stackoverflow.com/questions/6284599/locking-the-fields-in-mfmailcomposeviewcontroller/6287412#6287412 – Paresh Masani Sep 01 '13 at 10:09