(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
[inherit ('sys$library:starlet')]

program send_mail(input,output);

type
   item = record
             case boolean of
                true : (
                       buflen    : [word] 0..65535;
                       code      : [word] 0..65535;
                       bufadr    : integer;
                       retlenadr : integer;
                       );
                false : (zero : integer);
          end;

[external] function mail$send_begin(%immed cntx:integer;
                                    %immed itmlst1adr:integer;
                                    %immed itmlst2adr:integer):integer;
                                   extern;

[external] function mail$send_add_address(%immed cntx:integer;
                                          %immed itmlst1adr:integer;
                                          %immed itmlst2adr:integer):integer;
                                         extern;

[external] function mail$send_add_attribute(%immed cntx:integer;
                                            %immed itmlst1adr:integer;
                                            %immed itmlst2adr:integer):integer;
                                           extern;

[external] function mail$send_add_bodypart(%immed cntx:integer;
                                           %immed itmlst1adr:integer;
                                           %immed itmlst2adr:integer):integer;
                                          extern;

[external] function mail$send_message(%immed cntx:integer;
                                      %immed itmlst1adr:integer;
                                      %immed itmlst2adr:integer):integer;
                                     extern;

[external] function mail$send_end(%immed cntx:integer;
                                  %immed itmlst1adr:integer;
                                  %immed itmlst2adr:integer):integer;
                                 extern;

var
   itmlst0     : array [1..1] of item;
   itmlst1     : array [1..2] of item;
   cntx,stat   : integer;
   un,subj,txt : varying [80] of char;

begin
   un:='ISIS08'; (* username to send to *)
   subj:='Testing'; (* subject for MAIL *)
   txt:='This is a test of callable MAIL in VAX PASCAL'; (* text to send *)
   itmlst0[1].zero:=0;
   cntx:=0;
   stat:=mail$send_begin(iaddress(cntx),
                         iaddress(itmlst0),
                         iaddress(itmlst0));
   itmlst1[1].buflen:=un.length;
   itmlst1[1].code:=MAIL$_SEND_USERNAME;
   itmlst1[1].bufadr:=iaddress(un.body);
   itmlst1[1].retlenadr:=0;
   itmlst1[2].zero:=0;
   stat:=mail$send_add_address(iaddress(cntx),
                               iaddress(itmlst1),
                               iaddress(itmlst0));
   itmlst1[1].buflen:=subj.length;
   itmlst1[1].code:=MAIL$_SEND_SUBJECT;
   itmlst1[1].bufadr:=iaddress(subj.body);
   itmlst1[1].retlenadr:=0;
   itmlst1[2].zero:=0;
   stat:=mail$send_add_attribute(iaddress(cntx),
                                 iaddress(itmlst1),
                                 iaddress(itmlst0));
   itmlst1[1].buflen:=txt.length;
   itmlst1[1].code:=MAIL$_SEND_RECORD;
   itmlst1[1].bufadr:=iaddress(txt.body);
   itmlst1[1].retlenadr:=0;
   itmlst1[2].zero:=0;
   stat:=mail$send_add_bodypart(iaddress(cntx),
                                iaddress(itmlst1),
                                iaddress(itmlst0));
   itmlst1[1].buflen:=txt.length;
   itmlst1[1].code:=MAIL$_SEND_RECORD;
   itmlst1[1].bufadr:=iaddress(txt.body);
   itmlst1[1].retlenadr:=0;
   itmlst1[2].zero:=0;
   stat:=mail$send_add_bodypart(iaddress(cntx),
                                iaddress(itmlst1),
                                iaddress(itmlst0));
   stat:=mail$send_message(iaddress(cntx),
                           iaddress(itmlst0),
                           iaddress(itmlst0));
   stat:=mail$send_end(iaddress(cntx),
                       iaddress(itmlst0),
                       iaddress(itmlst0));
end.
