Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Is it possible to send an email in the background?

I want to take something that a user typed in a textarea and when they hit "Go" it will email it to a predefined email address.

Does anyone know how to go about doing this?

— asked October 13th 2010 by Bruce Ackerman
  • email
  • iphone
2 Comments
  • Interested in this also. Did you find a solution?

    — commented January 11th 2011 by Mike Hogan
  • I to am interested if a solution was found

    — commented February 7th 2011 by Hamish Rouse

3 Answers

  • You can try this:

    In Titanium mailSender.js

    
    //Variables
        var emailTo = "mymail@mail.com";
        var emailSubject= "my subject";
        var emailMessage = " My message ";
    
        var xhrURL = "http://myserver.com/email.php";
        var xhr_object = Ti.Network.createHTTPClient();
        xhr_object.open("POST", xhrURL, true);
    
    
        xhr_object.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" );
        xhr_object.setRequestHeader( "Connection" , "close" );
    
         //Post Data
         var postData = ({
    
            to : emailTo ,
            message : emailMessage,
            subject: emailSubject
            });
    
    
        xhr_object.send(postData);
    
        xhr_object.onload = function(){ 
            Titanium.API.info(this.responseText) //Log response
    
        }
    
        xhr_object.onerror = function(){ 
            alert("Error!")
        }
    

    then in the server email.php

    <?
        //get the vars from the post array
        $to = $_POST['to'] ;
        $subject = $_POST['subject'] ;
        $message = $_POST['message'] ;
    mail($to,$subject,$message);
    //For log variables var_dump($_REQUEST); 
    print "Mail sent";
    ?>
    
    — answered June 17th 2013 by Mario Alejandro Ramos Pérez
    permalink
    0 Comments
  • Would this work?

    var emailDialog = Titanium.UI.createEmailDialog();
    emailDialog.setSubject('Subject Name!');
    emailDialog.toRecipients = ['youremail@gmail.com'];
    emailDialog.setMessageBody('Hey! You should check out the App \n\nThe App is available for FREE on both the Apple App Store and the Android Marketplace!');
    
    emailDialog.SENT;
    

    I don't receive an email (i'm assuming because I'm still testing on my computer because I did the stand version of the code and still didn't receive an email)

    — answered October 13th 2010 by Bruce Ackerman
    permalink
    3 Comments
    • Sadly, no. emailDialog.SENT is simply a variable for an integer that is given when the user sends the Email. It just makes it easier for developers to not use the actual integer, cause using "emailDialog.SENT" is easier than (Just guessing here, I have no idea what the actual INT value is) "emailDialog.17740274".

      — commented October 13th 2010 by Colton Arabsky
    • Damn..

      — commented October 13th 2010 by Bruce Ackerman
    • Possible to mix something like this in? http://www.javascript-coder.com/javascript-form/javascript-email-form.phtml

      — commented October 13th 2010 by Bruce Ackerman
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.