From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 14-FEB-1991 14:33:45.54
To:	ARISIA::EVERHART
CC:	
Subj:	Re: Help using documented MAIL within VAX Pascal

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.83)
	 id AA23680; Thu, 14 Feb 91 11:47:57 EST
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Thu, 14 FEB 91 07:40:34 PST
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA14973; Thu, 14 Feb 91 07:29:18 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 14 Feb 91 15:10:31 GMT
From: usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!bronze!mdchaney@ucsd.edu  (M Darrin Chaney)
Organization: Indiana University, Bloomington
Subject: Re: Help using documented MAIL within VAX Pascal
Message-Id: <1991Feb14.151031.3309@bronze.ucs.indiana.edu>
References: <9102131200.AA11446@hac2arpa.hac.com>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <9102131200.AA11446@hac2arpa.hac.com> SYSTEM@MICKEY.dnet.hac.com writes:
>        Could someone provide some example code on how to utilise the
>        documented MAIL interface from within VAX Pascal ?

Here are two files.  The first is mail$routines.pas, which you can use to make
a .pen file.  The second is mailme.pas, which will mail a message.  It uses
a nice callable routine, so the code is easily adapted.

The reason for the extra .pen file is that starlet doesn't have the mail 
routines defined, although it has the constants for mail defined.  You may
wish to cut out the needed chunks and stick them in mail$routines so that you
don't have to include the entirety of starlet.

	Darrin
---

mdchaney@iubacs
mdchaney@bronze.ucs.indiana.edu
mdchaney@rose.ucs.indiana.edu

------mail$routines.pas--------pas/env=mail$routines/noobject mail$routines----
Module MailDef;

[Hidden] Type
   $BYTE = [BYTE] -128..127;             
   $WORD = [WORD] -32768..32767;         
   $QUAD = [QUAD,UNSAFE] RECORD          
      L0:UNSIGNED; L1:INTEGER; END;      
   $OCTA = [OCTA,UNSAFE] RECORD          
      L0,L1,L2:UNSIGNED; L3:INTEGER; END;
   $UBYTE = [BYTE] 0..255;               
   $UWORD = [WORD] 0..65535;             
   $UQUAD = [QUAD,UNSAFE] RECORD         
      L0,L1:UNSIGNED; END;               
   $UOCTA = [OCTA,UNSAFE] RECORD         
      L0,L1,L2,L3:UNSIGNED; END;         
   $PACKED_DEC = [BIT(4),UNSAFE] 0..15;  
   $DEFTYP = [UNSAFE] INTEGER;           
   $DEFPTR = [UNSAFE] ^$DEFTYP;          
   $BOOL = [BIT(1),UNSAFE] BOOLEAN;

(* Definition for the Callable Mail Functions                    *)

[Asynchronous,External(Mail$MailFile_Begin)] Function $MailFile_Begin (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_Close)] Function $MailFile_Close (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_Compress)] Function $MailFile_Compress (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_End)] Function $MailFile_End (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_Info_File)] Function $MailFile_Info_File (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_Modify)] Function $MailFile_Modify (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_Open)] Function $MailFile_Open (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$MailFile_Purge_Waste)] Function 
   $MailFile_Purge_Waste (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Begin)] Function $Message_Begin (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Copy)] Function $Message_Copy (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Delete)] Function $Message_Delete (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_End)] Function $Message_End (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Get)] Function $Message_Get (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Info)] Function $Message_Info (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Modify)] Function $Message_Modify (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Message_Select)] Function $Message_Select (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_Abort)] Function $Send_Abort (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_Add_Address)] Function $Send_Add_Address (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_Add_Attribute)] Function $Send_Add_Attribute (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_Add_Bodypart)] Function $Send_Add_Bodypart (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_Begin)] Function $Send_Begin (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_End)] Function $Send_End (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$Send_Message)] Function $Send_Message (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$User_Begin)] Function $User_Begin (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$User_Delete_Info)] Function $User_Delete_Info (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$User_End)] Function $User_End (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$User_Get_Info)] Function $User_Get_Info (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

[Asynchronous,External(Mail$User_Set_Info)] Function $User_Set_Info (
   Var Context : [Volatile] Integer;
   %REF InList : [UNSAFE] ARRAY [$l3..$u3:INTEGER] OF $UBYTE;
   %REF OutList : [UNSAFE] ARRAY [$l4..$u4:INTEGER] OF $UBYTE
   ) : Integer; External;

End.

--mailme.pas-------------------------------------------------------------------
[Inherit ('sys$library:starlet','mail$routines')]
Program Mail(Input,Output);

Type
   $UWORD = [Word] 0..65535;

   Item_List_Cell = Record
      Buffer_Length  : $UWORD;
      Item_Code      : $UWORD;
      Buffer_Address : Integer;  {May double as Item_Value}
      Item_Flags     : Integer;  {May double as Return_Address}
   End;                          {Use the function IAddress() to get an address}

   Item_List = Array [0..10] of Item_List_Cell;

Var
   User_List : Array [0..20] of Varying [80] of Char;

Function Init_Item_List_Cell(Var List_Cell:      Item_List_Cell;
                                 Buffer_Length:  $UWORD := 0;
                                 Item_Code:      $UWORD := 0;
                                 Buffer_Address: Integer := 0;
                                 Item_Flags:     Integer := 0):Integer;

Begin

   List_Cell.Buffer_Length:=Buffer_Length;
   List_Cell.Item_Code:=Item_Code;
   List_Cell.Buffer_Address:=Buffer_Address;
   List_Cell.Item_Flags:=Item_Flags;

   Init_Item_List_Cell:=1;

End; {Init_Item_List_Cell}

Function Send_Mail(UserList : Array [$l1..$u1:Integer] of 
                                       Varying [$l3] of Char;
                   To_Line  : Varying [$l4] of Char := '';
                   CC_Line  : Varying [$l5] of Char := '';
                   Subject  : Varying [$l6] of Char := '';
                   FileName : Varying [$l7] of Char := '' ):Integer;

Label
   Abort_And_Leave,Bye;

Var

   InList,OutList : Item_List;
   Status : Integer;
   Context : Integer;
   I,J : Integer;

Begin

   Init_Item_List_Cell(OutList[0],0,0,0,0);

   { Start the Mail context... }
   Init_Item_List_Cell(InList[0],0,0,0,0);

   { muy mucho importante! }
   Context:=0;

   Status:=$Send_Begin(Context,InList,OutList);
   If (Status <> 1) Then Goto Abort_And_Leave;

   { Make the second element the list end }
   Init_Item_List_Cell(InList[1],0,0,0,0);

   I:=0;

   Repeat
      Init_Item_List_Cell(InList[0],User_List[I].Length,mail$_send_username,
                          IAddress(User_List[I].Body),0);

      Status:=$Send_Add_Address(Context,InList,OutList);
      If (Status <> 1) Then Goto Abort_And_Leave;

      I:=I+1;
   Until (User_List[I].Length=0);

   J:=0;

   If (To_Line.Length<>0) Then
   Begin
      Init_Item_List_Cell(InList[J],To_Line.Length,mail$_send_to_line,
                          IAddress(To_Line.Body),0);
      J:=J+1;
   End;

   If (CC_Line.Length<>0) Then
   Begin
      Init_Item_List_Cell(InList[J],CC_Line.Length,mail$_send_cc_line,
                          IAddress(CC_Line.Body),0);
      J:=J+1;
   End;

   If (Subject.Length<>0) Then
   Begin
      Init_Item_List_Cell(InList[J],Subject.Length,mail$_send_subject,
                          IAddress(Subject.Body),0);
      J:=J+1;
   End;

   Init_Item_List_Cell(InList[J]);

   Status:=$Send_Add_Attribute(Context,InList,OutList);
   If (Status <> 1) Then Goto Abort_And_Leave;

   J:=0;

   If (FileName.Length<>0) Then
   Begin
      Init_Item_List_Cell(InList[0],FileName.Length,mail$_send_filename,
                          IAddress(FileName.Body),0);
      J:=J+1;
   End;

   Init_Item_List_Cell(InList[J]);

   Status:=$Send_Add_BodyPart(Context,InList,OutList);
   If (Status <> 1) Then Goto Abort_And_Leave;

   Init_Item_List_Cell(InList[0]);

   Status:=$Send_Message(Context,InList,OutList);
   If (Status <> 1) Then Goto Abort_And_Leave;

   Status:=$Send_End(Context,InList,OutList);
   If (Status <> 1) Then Goto Abort_And_Leave;

   Goto Bye;

Abort_And_Leave:

   $Send_Abort(Context,InList,OutList);

Bye:

   Send_Mail:=Status;

End;

Begin
   User_List[0]:='BACV5::MDCHANEY';
   User_List[1]:='';

   Send_Mail(UserList:=User_List,FileName:='Message.Txt');

End.
-------------------------------------------------------------------------------
Write back if you havve any problems...

	Darrin
-- 

mdchaney@iubacs
mdchaney@bronze.ucs.indiana.edu
mdchaney@rose.ucs.indiana.edu

