Sending emails with LiveCode

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kellymdeters
Posts: 23
Joined: Wed Oct 31, 2007 9:16 pm

Sending emails with LiveCode

Post by kellymdeters » Fri Sep 06, 2013 3:47 pm

I'm stuck!

At first I set up and was very successful sending emails from my standalone using the on-rev.com server that is my host (following these instructions: http://lessons.runrev.com/s/lessons/m/4 ... er-scripts). The problem that I hit is that, once again, the on-rev.com server has stopped sending ALL emails (for wordpress, photocart, machforms and other applications I have running on there as well as anything form my own .lc code that processes emails created in my standalone). I've submitted a support request for this problem but am still waiting. This happened about a year ago and eventually they got it fixed (not sure how or I'd suggest it to them again!), however this time around it's not just my activities that are being affected (wordpress, photocart, etc., were all sending emails to me notifying me of things as people interacted with my websites hosted on on-rev.com), but now I have a client using the stand-alone that needs to process emails and it's not working for her...which is a BIG issue! Since this has happened in the past and each time it happens there is no warning (you think you've sent the emails until people start complaining that they never got them), I do not want to rely on this for a client.

So I began to look into other ways of doing it.

1. I tried just using the revMail command, but that doesn't work for the message of the email as she needs to be able to send html emails (they have a table in them displaying the dancers' account charges, credits and balance - the stand alone is for a dance studio).

2. So then I found the instructions for using Thunderbird (which she DOES use, so bonus there!) (http://lessons.runrev.com/s/lessons/m/4 ... tml-e-mail) and it works beautifully for sending ONE email - and only if Thunderbird has been shut down prior to attempting to send that email. If I try to send multiple (the way the stand alone works is that she can select various groupings of dancers and click a button to "send account statements" and it processes and creates the email for each dancer's account), it will open the first one and then for each subsequent one I get a pop-up saying "only one Thunderbird may be open at a time." I also get this pop-up if I try to send one without first closing out the Thunderbird app (highly irritating as many people, including my client, leave their email app open all the time).

So, to sum up...
Sending multiple html emails through the server worked until my server quit doing it.
And then sending multiple emails through revMail command worked except that I need them to be html.
And finally sending html emails through Thunderbird worked except for when Thunderbird is already open and when I need to send more than one at a time (which is often!)

HELP PLEASE! :)

THANKS!!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Sending emails with LiveCode

Post by Mark » Mon Sep 09, 2013 1:00 am

Hi,

Which operating system do you use?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

kellymdeters
Posts: 23
Joined: Wed Oct 31, 2007 9:16 pm

Re: Sending emails with LiveCode

Post by kellymdeters » Wed Sep 11, 2013 5:57 pm

I use OSX to code but my dance studio client uses Windows and the mobile apps I've built are on iOS and Android

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Sending emails with LiveCode

Post by Mark » Wed Sep 11, 2013 11:45 pm

Hi,

I have tried the code from the "lesson". It works fine on Windows 8, except for the part that launches Thunderbird. I have to adjust the path to the executable.

Code: Select all

on mouseUp
   # declare the variable that holds the launch string
   local lvLaunchString
   # populate the launch string with data from the user interface
   put empty into lvLaunchString
   populateLaunchString lvLaunchString, "to=", "test@test.xyz"
   populateLaunchString lvLaunchString, "cc=", "test@test.xyz"
   populateLaunchString lvLaunchString, "subject=", "Test Subject"
   populateLaunchString lvLaunchString, "body=", the htmlText of field "Body Field"
   # populate the launch string with platform specific information for thunderbird
   if the platform is "MacOS" then # we are on a Mac
      put "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose" && lvLaunchString into lvLaunchString
   else if the platform is "Win32" then # we are on Windows
      if the systemVersion is "NT 6.2" then
         put "c:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe -compose" && lvLaunchString into lvLaunchString
      else
         put "c:\Program Files\Mozilla Thunderbird\thunderbird.exe -compose" && lvLaunchString into lvLaunchString
      end if
   else # we do not support this platform
      exit to top
   end if
   # launch the thunderbird compose window
   set the hideConsoleWindows to true
   open process lvLaunchString for update
   close process lvLaunchString
   wait 1 second with messages
   do fld 2 as VBScript
end mouseUp

# assemble tokens and arguments into the launch string
command populateLaunchString @pLaunchString avToken avArgument
    if avArgument is empty then exit populateLaunchString
    if pLaunchString is not empty then put pLaunchString & "," into pLaunchString
    put pLaunchString & avToken & "'" & avArgument & "'" into pLaunchString
end populateLaunchString
I have the following code in field 2:

Code: Select all

dim sendKeyObj
Set sendKeyObj = CreateObject("WScript.Shell")
sendKeyObj.SendKeys "^{ENTER}"
When I run this script, it creates a new e-mail, regardless of whether Thunderbird is running or not, and sends it automatically. Note that in my script, I replaced the fields at the start of the mouseUp handler with strings. You'll have to change that. You can do this in a repeat loop as well. For example if you have a list with e-mails you can do something like:

Code: Select all

  repeat for each line myAddress in myEMailList with messages
    populateLaunchString lvLaunchString, "to=", myAddress
    populateLaunchString lvLaunchString, "subject=", "Test Subject"
    populateLaunchString lvLaunchString, "body=", the htmlText of field "Body Field"
    -- remainder of script here
    wait 0 millisecs with messages
  end repeat
If this doesn't work on your client's computer, maybe she needs to update Thunderbird or buy a new computer ;-)
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Zood
Posts: 37
Joined: Mon Apr 24, 2017 7:17 pm

Re: Sending emails with LiveCode

Post by Zood » Fri Jun 16, 2017 12:11 pm

Hey mark,

You said the script creates AND sends the mail automatically. I,however cannot seem to make it send automatically?
The creating of the mail itself works like a charm but the sending-part does not work for me.
Got any tips on how to make those work?
Thanks!

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: Sending emails with LiveCode

Post by matthiasr » Mon Jun 19, 2017 2:50 pm

Hi Zood,

if you are using a commercial license of LC, like Indy or Business, then you could use the tsNET external for sending out emails.

I´ve uploaded a sample stack which shows basic email and ftp functions using the tsNet.

https://dl.qck.nu/?dl=lcMailAndFTP.livecode

Regards,
Matthias

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Sending emails with LiveCode

Post by AxWald » Wed Jun 21, 2017 2:15 pm

Hi,

for sending EMails on Win MailAlert does a very fine job for me.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply

Return to “Talking LiveCode”