Sending email in time...

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

Sending email in time...

Post by ctflatt » Tue Nov 22, 2011 4:10 pm

Hello, all.

I am developing a simple iOS/Android app that sends reminders as emailed SMS based on user preferences.

Is it possible to have the app "post" to a LC page which sends a precomposed message at a time in the future (say 45 minutes from the time it was posted)?

I currently host with On-Rev, but have no idea how to accomplish this, if it's possible.

Can anyone help guide me?

Many thanks!

:Todd

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

Re: Sending email in time...

Post by ctflatt » Wed Nov 30, 2011 2:00 pm

Either this is so simple I should be chastised for asking, or it's impossible, eh?

Anyone out there?

:Todd

PS. Klaus, thanks for cleaning up the spam... it is appreciated :)

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Sending email in time...

Post by bangkok » Wed Nov 30, 2011 6:15 pm

ctflatt wrote:Hello, all.

I am developing a simple iOS/Android app that sends reminders as emailed SMS based on user preferences.

Is it possible to have the app "post" to a LC page which sends a precomposed message at a time in the future (say 45 minutes from the time it was posted)?

I currently host with On-Rev, but have no idea how to accomplish this, if it's possible.

TO POST
-that's the easy part.
in your app, you put the address email for instance into leMessage. Then :

Code: Select all

   put "tobeanalysed="&urlencode(leMessage) into leMessage
   post leMessage to url "http://www.mysite.com/backoffice.irev
in backoffice.irev, on your on rev site :

Code: Select all

<?rev
put $_POST["tobeanalysed"] into leMessage
then, you write this information (leMessage) into a MySQL DB

TIME
-that's the tricky part from my point of view.
The only solution would be to create a "cron job"... that would execute a every XX minutes a .irev script that would read from the MySQL DB, looking for an email address.. and then sending the email, and then deleting etc.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

Re: Sending email in time...

Post by ctflatt » Thu Dec 01, 2011 12:29 pm

bangkok:

Thank you so much for responding! I really appreciate it.

I read and understand your example, but here is the twist... I do not want to "collect" email and send once every 45 minutes, but rather when the app posts to the page, each post is sent 45 minutes later. Does that make sense?

Is this possible:

IN THE APP

Code: Select all

put "tobeanalysed="&urlencode(tMessage) into tMessage
post tMessage to url "http://www.somesite.com/backoffice.lc"
IN THE BACKOFFICE.LC FILE

Code: Select all

<?lc
put $_POST["tobeanalysed"] into tMessage

--45 minutes, converted to seconds
wait 2700 seconds with messages

post tMessage to url "http://www.somesite.com/sendmail.php"
?>
Is this viable, or is this too taxing of the server? Should this work?

Thanks!

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Sending email in time...

Post by bangkok » Thu Dec 01, 2011 2:03 pm

Ok i understand.

From my experience you can not use the form "wait for XX minutes" within a irev script.

This is why, i thought about the cron job.

Regarding your rule 45 mn after post, there is I think a turn around :

-when you receive the post, you calculate the current time + 45 mn. You write this value into the database, along with the email text to be sent.

-after that, let's say your cron job launches the second irev script every minute. Within the script, you are going to look into the database for an email with a time = + or - 1 minute compared to the current time (AKA the time when the cron job is executed).

-you send the email, then you delete it or them from the DB.

You see ?

There might be other solutions, but that's the only one i can think of.

Post Reply

Return to “CGIs and the Server”