Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Mail output

edited March 2013 in Questions Posts: 7

Hello,

I was hoping someone could help me. I am making a program in which you can enter some data and the program should mail the output of the program. My program gives the correct output. But I was wondering if there is a way to copy this output to an email?
Thanks in advance :).

Tagged:

Comments

  • Jmv38Jmv38 Mod
    edited March 2013 Posts: 3,268

    I dont know how to do it directly with Codea. But you could do it indirectly:
    1/ write a php web page that can receive a file and sent by mail (i dont know how to do it but i've seen in the php doc it is possible).
    2/ make codea send the file to your web page via hhtp.request method

  • Posts: 7

    Ok thanks I'll try that ! :)

  • Posts: 502

    Use openurl("mailto://user@server")

  • Posts: 488

    Hello @KoBa. With the benefit of @tnlogy's advice, this page on the Codea Wiki may help.

  • Posts: 7

    Thanks for the comments. But in the example you still have to write the message in the code
    itself. I am trying to mail a couple of strings is this even possible with codea? Because the mailto comment does not take a string or table as an input.

  • Posts: 563

    .@KoBa - alternatively use the runtime and do it in Objective C. iOS6 makes it really easy to send an email, SMS, or post to twitter/facebook using the provided Activity View Controller class. For example:

            NSString *textToShare = @"Your text goes here";
            UIImage *imageToShare = [UIImage imageNamed:@"YourImage.png"];
            NSURL *urlToShare = [NSURL URLWithString:@"http://www.reefwing.com.au"];
            NSArray *activityItems = @[textToShare, imageToShare, urlToShare];
            
            UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities: nil];
            
            //  define the activity view completion handler
            
            activityVC.completionHandler = ^(NSString *activityType, BOOL completed)
            {
                NSLog(@"Activity Type selected: %@", activityType);
                if (completed)
                {
                    NSLog(@"Selected activity was performed.");
                }
                else
                {
                    if (activityType == NULL)
                    {
                        NSLog(@"User dismissed the view controller without making a selection.");
                    }
                    else
                    {
                        NSLog(@"Activity was not performed.");
                    }
                }
            };
            
            //  define activity to be excluded (e.g. save to Contact and Camera Roll)
            
            activityVC.excludedActivityTypes = [NSArray arrayWithObjects: UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, nil];
            
            [self presentViewController: activityVC animated: YES completion: nil];
    
  • Posts: 563

    interesting - the pre lang = "objc" trick doesn't seem to work.

  • Posts: 2,820

    Check out my post here: http://twolivesleft.com/Codea/Talk/discussion/1123/the-power-of-openurl#Item_5
    There is some code that demonstrates URL schemes. You'll find a scheme starting with "mailto://" which sends and email. Look here for a little more info: http://email.about.com/cs/standards/a/mailto_js.htm
    Good luck!

  • Posts: 7

    Thanks for all the help! It works ! :D

  • Posts: 7

    I was hoping someone could help me again. Sorry I'm totally new to Lua, so I don't exactly know what I'm doing :P. Anyway, I managed to insert a string in my program and show this string in an email. This works fine for one string. However, when I try to do this for multiple strings it doesn't work. I made a table of the strings and then used tostring on this table. The email shows table 0x... Is it even possible with tostring?
    Thanks in advance!

  • dave1707dave1707 Mod
    Posts: 5,996

    Is this something like what you're after.


    function setup()     to = "someone@email.com"     cc = "copy@email.com"     subject = "This is the subject"          str1="this is the first line"     str2="\nthis is the second line"     str3="\nthis is the third line"     message=str1..str2..str3          create(to, cc, subject, message) end function create(to, cc, subject, body)     url = "mailto:"..to.."?cc="..cc.."&subject="..code1(subject).."&body="..code1(body)     openURL(url) end function code1(str)     crlf = "%a%d-_.~"     return string.gsub(str, "[^"..crlf.."]", code2) end function code2(c)     return string.format ("%%%02X", string.byte(c)) end
  • Jmv38Jmv38 Mod
    Posts: 3,268

    Very cool @dave1707 . Thanks for sharing.

  • dave1707dave1707 Mod
    Posts: 5,996

    One thing I noticed with this is that leading spaces on a message line are ignored. I don't know if there's a way around it, or if that's just the way it is. So you can't format lines, they are all left justified.

  • Posts: 7

    @dave1707 Thanks! That's exactly what I need =D

  • Posts: 2,820

    The meathod that @dave1707 used is called a regular expression. To learn more about it, go to http://en.wikipedia.org/wiki/Regular_expression

  • Posts: 2,160

    @Zoyt, Technically lua doesn't have regular expressions built in. It uses patterns. They aren't as powerful as regular expressions, but are usually good enough.

  • edited August 2013 Posts: 436

    I'm using this code, to allow devices with iOS5 to send twits too:

    - (void)sendTwit:(const char*) text withImage:(const char*) image {
        TWTweetComposeViewController *tweeter = [
           [TWTweetComposeViewController alloc]
           init
        ];
        NSString *message = [NSString stringWithFormat:@"%s",text];
        NSString *img     = [NSString stringWithFormat:@"%s",image];
        [tweeter setInitialText:message];
        [tweeter addImage:[UIImage imageNamed:img]];
        [self.codeaViewController presentModalViewController:tweeter animated:YES];
     
    }

    you have to wait until Codea engine launch, there is an warning appearing if you call the function before that:

    <GKTurnBasedMatchmakerViewController: 0x21362f70> on <CodeaViewController: 0x1fd73b50> whose view is not in the window hierarchy!
    

    looks like there is no access directly to the main view that twetter needs...

    I would like to know if the Codea runtime library has an call to the tweeter send button when you use the capture button (video and image)

  • Posts: 7

    I wonder whether there is a way to let the program send an e-mail, without opening the mail app on the iPad. I found that it could be done using smtp. http://w3.impa.br/~diego/software/luasocket/smtp.html . However, I've read that the use of sockets in Codea is not possible. I was hoping someone could help me :), sorry I'm still new to al this stuff :P

  • possibly, if u use http.request parameter tables to post the data to a server which sends the data as an email

  • Posts: 2,820

    @juaxix - That's a deprecated class, just to let you know. You reminded me - I need to share my Obj-C classes. I'll do that soon. Mine contains tweeting, FaceBook, and saving to the camera roll.
    Thanks!

  • Posts: 16

    I would like to reanimate this thread to ask how I could attach a screenshot to Dave1707 's fantastic example. The first four lines should create the image, how can it be attached to the e-mail?

    function setup()
        myScreenshot = image(WIDTH,HEIGHT)
        setContext(myScreenshot)
           sprite("Platformer Art:Guy Look Right",WIDTH/2,HEIGHT/2)
        setContext()
    
    
        to = "someone@email.com"
        bcc = "copy@email.com"
        subject = "This is the subject"
    
        str1="this is the first line"
        str2="\n       this is the second line"
        str3="\n       this is the third line"
        message=str1..str2..str3
    
        create(to, bcc, subject, message, myScreenshot)
    end
    
    function create(to, cc, subject, body)
        url = "mailto:"..to.."?bcc="..bcc.."&subject="..code1(subject).."&body="..code1(body)
        openURL(url)
    end
    
    function code1(str)  crlf = "%a%d-_.~"
        return string.gsub(str, "[^"..crlf.."]", code2)
    end
    
    function code2(c)
       return string.format ("%%%02X", string.byte(c))
    end
    
  • dave1707dave1707 Mod
    Posts: 5,996

    @Surfer This is a simple mail format, and as far as I know, you can't send an image. It's just text.

  • Posts: 16

    Thanks @dave1707 , do you know if the image "myScreenshot" can be saved to the photoalbum then?

  • dave1707dave1707 Mod
    Posts: 5,996

    @Surfer Here's an example of saving the image to the Dropbox folder. It can be synced with the Dropbox app and once it's there, a lot of things can be done with it. For instance, it can be emailed to someone which is what I think you were trying to do with the above code.

    function setup()
        myScreenshot = image(WIDTH,HEIGHT)
        setContext(myScreenshot)
        sprite("Platformer Art:Guy Look Right",WIDTH/2,HEIGHT/2)
        setContext()
        saveImage("Dropbox:Guy",myScreenshot)
    end
    
    function draw()
        background(0)
        sprite(myScreenshot,WIDTH/2,HEIGHT/2)    
    end
    
  • Posts: 16

    Hi Dave!

    This will be good for internal use but I would like the user of my app to be able to send me a screenshot. I'm afraid having her or him use dropbox assets is around one corner too much.

    Could it be possible to trigger the original function of the ipad to do screenshots? That's pressing the round button on front and small button on top together. The image goes directly to the photoalbum then.

    Otherwise as a last option I will have to write the above instruction on screen and let the user do the screenshot manually.

    Thanks so much!

  • dave1707dave1707 Mod
    Posts: 5,996

    @Surfer I don't know right now if there's a way for someone to email you a screen shot using Codea. For now the best way is to do a screen shot which goes to the photo library. From the photo library, the image can be emailed to you.

Sign In or Register to comment.