Sending mail via libSMTP on cgi

Ken Ray kray at sonsothunder.com
Tue Aug 23 11:55:49 EDT 2005


On 8/23/05 9:25 AM, "Thomas McCarthy" <tominjapan at excite.com> wrote:

> There is egg on my cgi face.
> 1. form mail is only used for recieving submissions--not for sending out
> emails to various address.
> 
> 2. I tried plan B (use rev) I uploaded Andre's Raw SMTP stack (after adapting
> it for testing) Failed. Then I remembered my host won't allow sockets to be
> opened.
> 
> 3. Plan C: Ask the RevList.
> 
> I've already given up on the idea of running a rev chat program from my host
> server (socket problem, again). I may have to give up this idea as well.

Is your host server running Linux? If so, there should be a 'sendmail'
program either in the 'bin' or 'usr/bin' folders that you can use a Rev CGI
with. Here's an example of a CGI I use (based on Richard Gaskin's standard
CGI lib) that sends bug report emails to me from RevZilla (see the "mailMe"
handler for the good stuff). Obviously it can be adapted for general use.
(Watch for line wraps!)

-----------
#!mc

local sInArray, sCommand, sKeys, sOutData

--| RevZilla Bug Reporting CGI
--| Version: 1.1
--|
--|
--| Used for forwarding bug reports submitted on RevZilla

on startup
  StartCGI
  --
  put "Summary: " & sInArray["summary"] & cr & cr & "Description: " &
sInArray["desc"] & cr & cr & "From: " & sInArray["email"] into tMessage
  mailMe tMessage
  put "ok" into sOutData
      --
  EndCGI
end startup


on mailMe pMessage
  put "/usr/sbin/sendmail -t" into mprocess
  put "Bug report dated: " & (the short date) & cr & "----------" & cr & cr
& urldecode(pMessage) into pMessage
  
  open process mprocess for write
  
  write "From:" && "metacardcgi at sonsothunder.com" & cr to process mprocess
  write "To:" && "kray at sonsofthunder.com" & cr to process mprocess
  write "Subject:" && "RevZilla Bug Report" & cr & cr to process mprocess
  write pMessage & cr to process mprocess
  
  close process mprocess
  wait until the openprocesses is empty
end mailMe

--==============================================================--
-- 4w std cgi lib
--

on StartCGI
  put GetPostDataArray() into sInArray
  put the keys of sInArray into sKeys
  put sInArray["cmd"] into sCommand
end StartCGI

on EndCGI
  SendDataBackToClient sOutData
end EndCGI


function GetPostData
  global gTestlocal, gCgiIn
  if gTestlocal is true then
    return gCgiIn
  else
    if $REQUEST_METHOD is "POST" then
      put $CONTENT_LENGTH into tLen
      repeat
        read from stdin until empty
        put it after tInput
        if tLen = length(tInput) then
          exit repeat
        end if
      end repeat
      return tInput
    else
      put "Error calling CGI:  Data must be sent as POST."
    end if
  end if
end GetPostData


function GetPostDataArray
  put GetPostData() into tData
  split tData by "&" and "="
  return tData
end GetPostDataArray


on SendDataBackToClient
  global gTestlocal, gCgiOut
  if gTestlocal is true then
    put sOutData into gCgiOut
  else
    put "Content-Type: text/html" & crlf &\
        "Content-Length:"&& length(sOutData) & crlf & crlf
    put sOutData
  end if
end SendDataBackToClient

Enjoy!



Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com





More information about the use-livecode mailing list