Article 169628 of comp.os.vms:

In article <01bc5dcc$6fde9160$44a8b8cd@velu.ix.netcom.com>, "Data64" <Data64@geocities.com> writes...
>Essentially I need to be able to mail text files from my
>Fortran program. I am on Vax VMS 5.5-2.

I'll include a simple FORTRAN example. For error handling, be sure to read
up on the MAIL$_NOSIGNAL (sp?) item list entry in the Callable Mail  
chapter tin the Callable Utilities manual (Hmmm, was mail only documented
with 6.0 or was that 5.5? The code was there all along)

      implicit integer(a-z)

      include '($MAILDEF)' ! 
      include '($RMSDEF)'  ! only need RMS$_EOF

      ! success and error routines
      external send_success , send_error 

      Integer Status ! return status
      Integer context , user_context

      character*255 file_name
      integer       file_name_length
      character*255 user_name
      integer       user_name_length
      character*255 subject
      integer       subject_length
      character*255 personal_name
      integer       personal_name_length
      character*255 transport 
      integer       transport_length

      ! define list structure
      structure /item_list/
        union
          map
             integer*2 buflen, itmcod
             integer*4 bufadr, retadr
          end map
          map
              integer*4 end_list
          end map
        end union
      end structure

      ! most mail$ routine have the format ( context, item_list, item_list )

      record /item_list/null_list    ! used where item list has no codes
      record /item_list/in_list(5)  ! input list
      record /item_list/file_list(5)  ! input list
      record /item_list/user_list(5)  ! input list
      record /item_list/send_list(5)  ! input list
      record /item_list/subject_list(5)  ! input list

      null_list.end_list = 0   ! null list

      ! get the filespec
      status = lib$get_input( file_name , 'Filename: ', file_name_length )
      if (.NOT. status ) then
           if (status .EQ. rms$_eof ) then
                Call sys$exit( %VAL(1) )  
           else
                call lib$signal ( %val( status ) )
           end if
      endif

      ! get the TO: user
      status = lib$get_input( user_name , 'To: ', user_name_length )
      if (.NOT. status ) then
           if (status .EQ. rms$_eof ) then
                Call sys$exit( %VAL(1) )  
           else
                call lib$signal ( %val( status ) )
           end if
      endif

      !+
      ! setup the item lists once
      !-

      ! better have a file or in big trouble
      file_list(1).buflen = file_name_length 
      file_list(1).itmcod = mail$_send_filename
      file_list(1).bufadr = %LOC( file_name )
      file_list(1).retadr = 0
      file_list(2).end_list = 0   ! null list


      user_list(1).buflen = user_name_length
      user_list(1).itmcod = mail$_send_username
      user_list(1).bufadr = %LOC( user_name )
      user_list(1).retadr = 0
      user_list(2).buflen = 2
      user_list(2).itmcod = mail$_send_username_type
      user_list(2).bufadr = %LOC( mail$_to )
      user_list(2).retadr = 0
      user_list(3).end_list = 0   ! null list


      if ( subject_length .GE. 1 ) then
           item_count = item_count + 1
           subject_list(1).buflen = subject_length 
           subject_list(1).itmcod = mail$_send_subject     
           subject_list(1).bufadr = %LOC( subject )
           subject_list(1).retadr = 0
           subject_list(2).end_list = 0   ! end list 
      else
           subject_list(1).end_list = 0   ! end list
      end if

      send_list(1).buflen = 4
      send_list(1).itmcod = mail$_send_success_entry
      send_list(1).bufadr = %LOC( send_success )
      send_list(1).retadr = 0
      send_list(2).buflen = 4
      send_list(2).buflen = mail$_send_error_entry
      send_list(2).bufadr = %LOC( send_error )
      send_list(2).retadr = 0
      send_list(3).end_list = 0   ! end list

      !+
      !  Ready to send the message by sending the input file
      !-

      context = 0

      status = mail$send_begin( context, null_list, null_list )
      if ( .NOT. status ) then
              ! mail signals error
              ! call lib$signal ( %val( status ) )
              ! something bad happen so I can not continue
              stop
      end if

      status = mail$send_add_address( context, user_list, null_list )
         ! if ( .NOT. status ) call lib$signal ( %val( status ) )

      status = mail$send_add_attribute( context, subject_list, null_list )
         ! if ( .NOT. status ) call lib$signal ( %val( status ) )

      status = mail$send_add_bodypart( context, file_list, null_list )
         ! if ( .NOT. status ) call lib$signal ( %val( status ) )

      if ( .NOT. status ) then 
              ! if could not specify the file, abort sending the message
      		status = mail$send_abort( context, null_list, null_list )
              if ( .NOT. status ) call lib$signal ( %val( status ) )
      else
              status = mail$send_message( context, send_list, null_list )
              ! if ( .NOT. status ) call lib$signal ( %val( status ) )
      end if

      status = mail$send_end( context, null_list, null_list )
         ! if ( .NOT. status ) call lib$signal ( %val( status ) )

      END

      integer function  send_success ( recipient )

      implicit integer(a-z)

      character*(*) recipient

      type *, 'sent message to ' , recipient 

      send_success = 1 ! success

      END

      integer function  send_error ( recipient )

      implicit integer(a-z)

      character*(*) recipient

      type *, 'Unable to send to ' , recipient

      send_error = 1 ! 

      END



Hope this helps,                +--------------------------------------+
Hein van den Heuvel, Digital.   | All opinions expressed are mine, and |
  "Makers of VMS and other      | may not reflect those of my employer |
   fine Operating Systems."     +--------------------------------------+


