Email Using LiveCode Server?

Alex Tweedly alex at
Mon Apr 21 17:33:28 EDT 2014

See below (based, I think, on that same example but I may have modified 
it ... not sure now, I've been through a few differnet versions based on 
this and another similar sample). This is in use on on-rev (pancake)

-- Alex.

-- send an email
command mail pTo, pSub, pMsg, pFrom, pCc, pBcc, pHtml, pAtts
     local tMsg

     -- build the message header, adding the from, to and subject details
     -- we also put any cc addresses in here, but not bcc (bcc addresses 
     put "From:" && pFrom & return & "To:" && pTo & return & "Subject:" 
&& pSub & \
     return into tMsg    if pCc is not empty then
         put "Cc:" && pCc & return after tMsg
     end if

     -- if there are any attachments, we must send this email as multipart
     -- with the message body and each attachment forming a part
     -- we do this by specifying the message as multipart and generating 
a unique boundary
     if pAtts is an array then
         local tBoundary
         put "boundary" & the seconds into tBoundary
         put "MIME-Version: 1.0" & return & "Content-Type: 
multipart/mixed; boundary=" & \
         wrapQ(tBoundary) & return & "--" & tBoundary & return after tMsg
     end if

     -- add the actual message body, setting the content type appropriately
     if pHtml is true then
         put "Content-Type: text/html;" & return & return after tMsg
         put "Content-Type: text/plain;" & return & return after tMsg
     end if
     put pMsg & return after tMsg

     -- add each attachment as a new part of the message, separating using
     -- the generated boundary
     if pAtts is an array then
         put "--" & tBoundary & return after tMsg
         repeat for each element tAtt in pAtts
             if there is a file tAtt["path"] then
                 if tAtt["type"] is empty then
                     get "application/octet-stream"
                     get tAtt["type"]
                 end if
                 put "Content-Type:" && it & "; name=" & 
wrapQ(tAtt["name"]) & ";" & \
                 return & "Content-Transfer-Encoding: base64;" & return 
& return & \
                 base64Encode(URL ("binfile:" & tAtt["path"])) & return 
& "--" & \
                 tBoundary & return after tMsg
             end if
         end repeat
     end if

     -- send the mail by piping the message we have just built to the 
sendmail command
     -- we must also send a copy of the message to the bcc addresses
     get shell("echo" && wrapQ(shellEscape(tMsg)) && "| 
/usr/sbin/sendmail" && \
     wrapQ(shellEscape(pTo)) && "-f" && wrapQ(shellEscape(pFrom)))
     if pBcc is not empty then
         get shell("echo" && wrapQ(shellEscape(tMsg)) && "| 
/usr/sbin/sendmail" && \
         wrapQ(shellEscape(pBcc)) && "-f" && wrapQ(shellEscape(pFrom)))
     end if
     put "MAIL sent" && the seconds & CR & \
           "TO:" && pTo & CR & \
           "SUBJ:" && pSub & CR &CR after URL ("file:./log_mail.txt")
end mail

--  escape shell characters: use this function before passing data to 
the shell
function shellEscape pText
    repeat for each char tChar in "\`!$" & quote
       replace tChar with "\" & tChar in pText
    end repeat
    return pText
end shellEscape

-- wrap quotes around text
function wrapQ pText
    return quote & pText & quote
end wrapQ

On 21/04/2014 19:51, Scott Rossi wrote:
> Hi All:
> I'm wondering if anyone has a working example of sending email from
> LiveCode server.
> I'm trying to send mail using LC server on a site, and following the RunRev
> lesson:
> rver-Scripts
> LC is working, the mail form is working, everything *appears* to be
> working,
> but no mail is being sent from the server.  I tried to get the result at
> the end of the mail script and all I get is "0". I'm not sure if that
> means false, but I suppose that might make sense since no mail is being
> sent.  I've looked around online and found related examples, tried some
> different flags, but several hours later still no success.  I give up.
> Maybe I'm missing some additional file or configuration setting somewhere?
> This is hosted on DreamHost if that helps.
> Thanks & Regards,
> Scott Rossi
> Creative Director
> Tactile Media, UX/UI Design
> _______________________________________________
> use-livecode mailing list
> use-livecode at
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

More information about the Use-livecode mailing list