OpenVMS Source Code Demos
SFF_DEMO_BASIC
1000 !============================================================================================
! title : SFF_DEMO_BASIC_101.BAS
! author : Neil Rieck
! created: 2014/11/19
! build : $bas sff_demo_basic_101
! $link sff_demo_basic_101 , -
! sys$input/opt
! sys$share:tcpip$smtp_mailshr.exe/share
! notes :
! 1) tcpip_send_from_file() only works with "TCPIP Services for OpenVMS"
! 2) contents of my static test file "sff_demo.txt" -----------------------------------------
! MAIL FROM:<[email protected]> <--- no w/s after the colon
! RCPT TO:<[email protected]> <--- no w/s after the colon
! DATA
! Date: Wed, 19 Nov 2014 14:48:14 -0400 <<--- should use the current UTC
! Message-Id: <[email protected]> <<--- change to avoid some spam tests
! From: [email protected] (Funny Stuff)
! To: [email protected]
! Subject: Test of SFF mechanism
! <<--- blank line is recommended
! This is the message text. Whatever. <<--- body
! -------------------------------------------------------------------------------------
! 3) tcpip_send_from_file() requires that your data begins immediately after the colon in fields
! "MAIL FROM:" and "RCPT TO:". No spaces or tabs. This is an oddity of tcpip_send_from_file
! because you can use white-space when connecting directly to port 25
! 4) "Message-Id:" is not mandatory but some anti-SPAM detectors require it. It must be unique
! because:
! 4a. some pop3 servers will throw away duplicate mail based upon "Message-Id:"
! 4b. some smtp clients will remember that you deleted a message with "Message-Id:" then
! will auto-delete new mail containing the same "Message-Id:" (Office Outlook does this)
! 5) "Date" is not mandatory but some anti-SPAM detectors require it
! 5a. This is nice to have since SMTP messages can be delayed by up to 4 hours
! 5b. some anti-SPAM detectors consider old stamps (which go to the bottom of a smtp message
! window) as suspicious.
! 5c. some anti-SPAM detectors consider future stamps (which go to the top of a smtp message
! window) as suspicious.
! history:
! ver who when what
! --- --- -------- --------------------------------------------------------------------------
! 100 NSR 20141119 1. original effort
! 101 NSR 20141121 1. added code to generate a dynamic xfer file
!============================================================================================
option type=explicit ! no kid stuff
!
external long function tcpip$smtp_send_from_file(string by ref, string by ref, long)
external string function wcsm_dt_stamp16 !
external string function wcsm_get_mime_time !
external string function wcsm_trnlnm(string) ! needed by wcsm_get_mime_time()
!
! why use a mapped string? Like "C" strings, they are passed by address where-as
! unmapped strings are passed by descriptor
!
map(abc)string ms1 = 99 ,&
string ms2 = 99
!
declare long rc% ,&
long debug% ,&
long junk% ,&
long handler_error% ,&
string dt$ ,&
string fs1$
!=======================================================================
! main
!=======================================================================
2000 main:
dt$ = wcsm_dt_stamp16 ! ccyymmddhhmmsstt
fs1$ = "smtp-scratch-"+ dt$ +".txt" !
!
when error in !
print "-i-opening file: "+ fs1$
open fs1$ for output as #99 &
,organization sequential &
,recordsize 32000
print "-i-writing file: "+ fs1$
print #99, "MAIL FROM:<[email protected]>"
print #99, "RCPT TO:<[email protected]>"
print #99, "DATA"
print #99, "Date: "+ wcsm_get_mime_time
print #99, "Message-Id: <"+ dt$ +"@dilbert.com>"
print #99, "From: [email protected] (Funny Stuff)"
print #99, "To: [email protected]"
print #99, "Subject: Test of SFF mechanism"
print #99, ""
print #99, "Test of SFF mechanism. Whatever."
print "-i-closing file: "+ fs1$
close #99
handler_error% = 0 ! all is well
use !
handler_error% = err ! oops
end when !
if handler_error% <> 0 then !
print "-e-error:";handler_error%;"so will exit" !
goto fini !
end if !
!
print "-i-calling tcpip$smtp_send_from_file()" !
ms1 = fs1$ + chr$(0) ! needs to look like a "C" string
ms2 = chr$(0) ! needs to look like a "C" string
debug% = 9 !
rc% = tcpip$smtp_send_from_file(ms1, ms2, debug%) !
print "-i-return code:";rc%; ! no EOL here
junk% = rc% and 7% ! break down the return code bits
if junk% <> 1 then !
print " ("+ str$(junk%) +")" ! summary w/EOL
else !
print ! EOL
end if !
when error in
print "-i-deleting file: "+ fs1$
kill fs1$
use
end when
!
! Adios
!
fini:
32000 end !
!
32100 %include "[.fun]WCSM_GET_MIME_TIME.fun"
!
32110 %include "[.fun]wcsm_dt_stamp16.fun"
!
32120 %include "[.fun]wcsm_trnlnm.fun"
!