Mike: here is my EMAIL.TO.SENDMAIL subroutine
all programs call this subroutine to send email. Notice how I changed original text message to be html message. Also the usage of 'pre' and '/pre'. This is running on QM/Linux.
good luck.
SUBROUTINE EMAIL.TO.SENDMAIL(EMO.ID,EMO.FILE) *
***
Linux sendmail:
*** -t Read message for recipients.
*** To:, Cc:, and Bcc: lines will be scanned for recipient addresses.
*** The Bcc: line will be deleted before transmission.
!
* 11-01-07 smt outbound email via linux
sendmail
* delete EMO.FILE,EMO.ID and then * re-write to EMO.FILE with ID = TO.ADDR_seqno
* modifications:
* 08-20-12 smt added Content-Type: text/html;
* 08-04-08
smt per wikipedia.org - valid email address characters are: * uppercase and lowercase letters
* digits 0 thru 9
* characters ! # $ % * / ? | ^ { } ` ~ & ' + - = _
* character . provided that it is NOT the 1st nor last character, nor may it appear two or more times consecutively
*
* 11-06-07 smt if EMO.ID = contactus - send copy of email to sender !
$DEBUG
OPENPATH \/tmp/\ to TMP.FILE ELSE GOTO 20000
!
READ EMO.REC FROM EMO.FILE,EMO.ID ELSE CRT \could NOT read \:EMO.ID:\ from EMAIL out file...\ GOTO 20000
END
*
TMP.REC = EMO.REC
FOR II = 1 TO 5
TMP.REC = DELETE(TMP.REC,1,0,0) ; * get rid of attributes SENDMAIL does NOT need
NEXT II
*
DONEHTML = 0
IF INDEX(TMP.REC,\text/html;\,1) THEN DONEHTML = 1
IF NOT(DONEHTML) THEN
IF INDEX(TMP.REC,\TEXT/HTML;\,1) THEN DONEHTML = 1
END
IF
NOT(DONEHTML) THEN
NUMAM = DCOUNT(TMP.REC,@AM)
FOR II = 1 TO NUMAM
XX$ = OCONV(TMP.REC<II>,"MCU")
IF INDEX(XX$,\X-MAILER\,1) THEN
II+= 1
DONEHTML = 1
TMP.REC = INSERT(TMP.REC,II,0,0,\<pre>\)
TMP.REC = INSERT(TMP.REC,II,0,0,\<body>\)
TMP.REC = INSERT(TMP.REC,II,0,0,\</head>\)
TMP.REC =
INSERT(TMP.REC,II,0,0,\<head>\)
TMP.REC = INSERT(TMP.REC,II,0,0,\<html>\)
TMP.REC = INSERT(TMP.REC,II,0,0,\ \)
TMP.REC = INSERT(TMP.REC,II,0,0,\Content-Type: text/html;\)
TMP.REC = INSERT(TMP.REC,II,0,0,\MIME-Version: 1.0\)
II = NUMAM
END
NEXT II
*
IF DONEHTML THEN
TMP.REC<-1> = \</pre>\
TMP.REC<-1> = \</body>\
TMP.REC<-1> = \</html>\
END
END
*
TMP.SQNO = 1
LOOP
READ XTMP.REC FROM TMP.FILE,TMP.ID ELSE XTMP.REC = '' UNTIL XTMP.REC = '' DO
TMP.SQNO+= 1
REPEAT
WRITE TMP.REC ON TMP.FILE,TMP.ID !
100 * begin processing
!
REPLY.ADDR = FIELD(EMO.REC<11>,":",2)
REPLY.ADDR = FIELD(REPLY.ADDR,",",1) ; * only 1 email address for 'reply.addr'
*** in the CONTACTUS.HTM this is the TOWHO variable in hexidecimal
*** valid characters
* uppercase and lowercase letters
* digits 0 thru 9
* characters ! # $ % * / ? | ^ { } ` ~ & ' + - = _
*
*** remove these characters in email address
*
BADCHARS = \(),\ ; * leave . "
BADCHARS:= "\" ; *
0123456789 leaving the numbers in there
BADCHARS:= ":;" ; * leave @ <>
BADCHARS:= "[]"
*
CONVERT BADCHARS TO '' IN REPLY.ADDR
*
OUTBOUND.ADDR = EMO.REC<4> ; * [To:]
PRIMARY.TO.ADDR = FIELD(OUTBOUND.ADDR,",",1) ; * used to send copy of email to
COPY.ADDR = FIELD(EMO.REC<5>,":",2) ; * multiple separated by commas [Bcc:]
*
CONVERT \,\ TO @VM IN OUTBOUND.ADDR
CONVERT \,\ TO @VM IN COPY.ADDR
*
NUMVM = DCOUNT(OUTBOUND.ADDR<1>,@VM)
FOR ZZZ = 1 TO NUMVM
TO.ADDR = OUTBOUND.ADDR<1,ZZZ>
GOSUB 500 ; * send mail
NEXT ZZZ
*
*** now any Bcc
*
NUMVM = DCOUNT(COPY.ADDR<1>,@VM)
FOR ZZZ = 1 TO NUMVM
TO.ADDR = COPY.ADDR<1,ZZZ>
GOSUB 500 ; * send mail
NEXT ZZZ
*
*** now send copy to the 'From:' email address(es)
*
TO.ADDR = REPLY.ADDR ; REPLY.ADDR = PRIMARY.TO.ADDR
TMP.REC<1> = \From:\:REPLY.ADDR
TMP.REC<3> = \To:\:TO.ADDR
*
AMC$ = 6
LOOP
VAL$ = TMP.REC<AMC$>
UNTIL VAL$ = '' DO
AMC$+= 1
REPEAT
*
PLN = \You sent the following email to \:REPLY.ADDR:\ .\
TMP.REC =
INSERT(TMP.REC,AMC$,0,0,PLN)
WRITE TMP.REC ON TMP.FILE,TMP.ID *
AMC$ = 6
LOOP
VAL$ = EMO.REC<AMC$>
UNTIL VAL$ = '' DO
AMC$+= 1
REPEAT
*
EMO.REC = INSERT(EMO.REC,AMC$,0,0,PLN)
*
GOSUB 500
END
*
GOTO 20000
!
500 * send outbound email via SENDMAIL
!
*
*** remove these characters in email address
*
BADCHARS = \(),\ ; * leave . "
BADCHARS:= "\" ; * 0123456789 leaving the numbers in there
BADCHARS:= ":;" ; * leave @ <>
BADCHARS:= "[]"
*
CONVERT BADCHARS TO '' IN REPLY.ADDR
*
VERB = \sendmail -f\:REPLY.ADDR:\ \:TO.ADDR:\ < /tmp/\:TMP.ID CRT \ \
CRT \email.to.sendmail...\
CRT VERB
OS.EXECUTE VERB
*
SLEEP 1
*
*** write out with new id (so can track by TO.ADDR)
*
NEW.EMO.ID = OCONV(TO.ADDR,"MCU") ; SQNO = 1 ; DONE = 0 LOOP UNTIL DONE DO
IF NEW.EMO.REC # '' THEN
SLEEP 1
END ELSE
DONE = 1
END
REPEAT
*
RETURN
!
20000 * end of program
!
RETURN
END
Computerized Data Mgmt Inc (CDMI)