Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Sending emails without smtp - a hack

From: chris::starforge::co::uk at: 13-Mar-2001 19:56

Hi, Those on the list who have good memories may remember that, a few weeks ago, I was talking about sending emails from a server with no SMTP support. In order to send emails I have to invoke /usr/sbin/sendmail directly, something not possible from /core Directly anyway ;)) My thinking was this - write a function that generated a files containing the email header and body, then use a perl cgi script that invoked /usr/sbin/sendmail, throwing the contents of the file at it. I gave up with the perl part (yea Gods, that language is foul..) and wrote a standard shell script to do it instead. The results are: REBOL [ Title: "Email wrapper function" Date: 13-Mar-2001 Version: 1.0.1 File: %emailer.r Author: "Chris Page" Rights: "Copyright (c) Chris Page 2001" Email: [chris--starforge--co--uk] Home: Purpose: { The functions in this script abstract the REBOL email facility away from the reliance on a system with SMTP capability. In combination with a PERL script called emailer.cgi, this can support email facilities on any system with the required capabilities. } History: [ 1.0.0 [11-Mar-2001 { Initial code } "Chris Page"] 1.0.1 [13-Mar-2001 { Corrected errors in the header creation, finally got a working cgi script to forward emails generated by this script.. } "Chris Page"] ] Comment: { It is pretty obvious that this is going to have problems if a lot of emails need to be send concurrently. As such it is not suitable for a very heavy traffic site.. } ] ; Set this to false if you do not have smtp facilities useInternal: false ; Placed in the from: header field, change it to *your* address please :)) fromAddress: [chris--starforge--co--uk] sendemail: func [ "Send an email using through the abstration layer" recipient [email! block!] "address(es) of the destination(s)" subject [string!] "text to put in the subject line" bodytext [string!] "text of the email" ][ either useInternal [ header: make system/standard/email [ Subject: subject ] send/header recipient bodytext header ][ if email? recipient [recipient: reduce [recipient]] dest: make string! 1024 num: 1 foreach addr recipient [ if email? addr [ either num > 1 [ append dest rejoin ["," addr] ][ append dest addr ] num: num + 1 ] ] header: reduce [ {To: } dest "^/" {From: } fromAddress "^/" {^/^/}] write %tempdata.dat rejoin [ header bodytext ] read delete %tempdata.dat ] ] This is the emailer.cgi script: #!/bin/sh echo "Content-Type: text/plain" echo "" echo "" /usr/sbin/sendmail -t < tempdata.dat echo "Done" It's a bit hacky, but in the absence of a system or exec function in REBOL this is the best I can think up. BTW: it is possible to modify the shell script to accept a filename as a query string parameter. That may be a possible workaround for the concurrency problem if some form of random number is used in the filename. Chris -- New sig in the works Explorer 2260, Designer and Coder -- Sattinger's Law: It works better if you plug it in.