From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 29-SEP-1988 02:58
To:	ARISIA::EVERHART
Subj:	RE: Mail from a detached process


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Wed, 28 SEP 88 22:58:55 PDT
Received: from CUNYVM.CUNY.EDU by KL.SRI.COM with TCP; Wed, 28 Sep 88 22:31:52 PDT
Received: from UALR.BITNET by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with BSMTP id 5685; Wed, 28 Sep 88 22:26:20 EDT
Date: Wed, 28 Sep 88 21:17 CDT
From: Dale Miller <DOMILLER%UALR.BITNET@CUNYVM.CUNY.EDU>
Subject: RE: Mail from a detached process
To: INFO-VAX@KL.SRI.COM
X-VMS-To: IN%"INFO-VAX@KL.SRI.COM"

>
>I have a FORTRAN program which I run as a detached process.  If it
>executes a certain set of instructions, I want it to mail me a message
>to let me know that something is going on.  Normally, I could use
>LIB$SPAWN, but LIB$SPAWN doesn't work from a detached process.  What
>would be the easiest way to have it send me mail?  Any ideas?
>
>                    Lee Cox
>                    Academic VAX Systems
>                    Texas A&M University
>                    SYSVAX@TAMVENUS.BITNET
>                    SYSVAX@VENUS.TAMU.EDU
>
My solution is to use an un-documented interface to VAX MAIL.  This program
will only work if you have DECNET installed and running on your machine, and
has not been tested under V5.0 (I'm still on 4.7), but I expect that it will
still work.  Listing follows:
------------------- Cut here ---------------------------------------------
c       Sample mainline to call MAILT
        implicit none
        include '($syidef)'
        character*6  node
        character*32 from_name
        character*32 to_name
        character*32 to_show
        character*32 subject
        character*80 text(20)/20*' '/
        integer istat,mailt

        call lib$getsyi(syi$_nodename,,node,,,)

        from_name = 'DETACHED'          ! Note that this name does NOT have
                                        ! to be a valid username
        to_name   = 'DOMILLER'
        to_show   = 'DOMILLER'
        subject   = 'Testing'
        text(1)   = 'This is line 1 of my message'
        text(2)   = 'This is line 2'

        istat = mailt(node,from_name,to_name,to_show,subject,text)
        if(istat) then
            type*,'Send failed'
            end if
        end
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c       MAIL.FOR
c       This program will send a message to a user using the VAX/VMS
c       "handle" via DECnet.  Based on a BASIC program from "VAX Professional"
c
c       Dale Miller - UALR
c
c       Rev. 1.0  26-Jan-1987
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

        integer function mailt(
        1   node,                       ! Node to send to &
        2   from_name,                  ! FROM name &
        3   to_name,                    ! List of TO names @ node &
        4   to_show,                    ! What to show in TO field &
        5   subject,                    ! Subject &
        6   text)                       ! Text array

        implicit none

        character*6  node
        character*32 from_name
        character*32 to_name
        character*32 to_show
        character*32 subject
        character*80 text(20)

        integer istat,len,mlen,i
        integer str$trim,str$upcase

        logical errchk

 1001   format(a)

c       Fix case
        istat=str$upcase(node,node)
        istat=str$upcase(to_name,to_name)

c       Open the link to the mail task, and handle errors

        istat=str$trim(node,node,len)

        open(unit=1,                            ! Open channel to MAIL server
        1   file=node(1:len)//'::"27="',
        2   access='sequential',
        3   form='formatted',
        4   carriagecontrol='none',
        5   status='new')

c       Send the FROM information

        istat=str$trim(from_name,from_name,len)
        write(1,1001,err=9999) from_name(1:len)
c       Send each message which states who should receive the text on the
c       other side. ALWAYS CHECK what status the MAIL server gives back.

        write(1,1001,err=9999) to_name

        if (errchk(0)) go to 9999               ! Check if MAIL server accepted
c       Terminate the list of receivers with a one byte null record

        write(1,1001,err=9999) char(0)
c       Send the text that shows up in the TO: field of mail

        istat=str$trim(to_show,to_show,len)
        write(1,1001,err=9999) to_show(1:len)
c       Write the subject line to the DECnet link.

        istat=str$trim(subject,subject,len)
        write(1,1001,err=9999) subject(1:len)   ! Put the text
c       Read in each line of text and send it across line by line.
c       This can be optimized to send one long chunk.

        mlen=20
        do while (text(mlen).eq.' ')
            mlen=mlen-1
            end do
        do i=1,mlen
            istat=str$trim(text(i),text(i),len)
            write(1,1001,err=9999) text(i)(1:len)       ! Put the text
            end do

c       Write end of text message.

        write(1,1001,err=9999) char(0)          ! Put null byte
c       Loop through and receive the status code for all users
c       the mail was sent to.

        if(errchk(0)) go to 9999                ! Go check error, print msgs
c       Finished, go close up shop

        close(unit=1)
        mailt=0
        return

 9999   Continue                                ! Error return
        close(unit=1)
        mailt=1
        return
        end









        logical function errchk(x)
c       Check to see if the message just sent was received ok; or, check
c       what the incoming message from the MAIL server says.
c       This routine will dump error text to the terminal
        implicit none
        character*255 mess
        integer len
        integer x,dummy

 1002   format(q,a)
        read(1,1002,err=2000)len,mess
        dummy=ichar(mess(1:1))
        if((dummy.and.1).eq.1) then             ! Success?
            errchk=.false.
            return
            end if

c       Come here if an error was received


 0020   continue
        read(1,1002,err=2000)len,mess(1:len)    ! Get text/terminator indication

        if(len.ne.1) then                       ! If len <> 1, must be text
            print*,mess(1:len)                  ! so print it
            go to 0020                          ! and loop for possibly more
            end if
        if(ichar(mess(1:1)).ne.0) go to 20      ! 0 byte means all done
        errchk=.true.
        return
 2000   print*,'%Network communications error'
        errchk=.true.
        end

--------------------------------------------------------------------------
| Dale O. Miller                        | #   #  ###  #     ####         |
| University of Arkansas at Little Rock | #   # #   # #     #   #        |
| 2801 S. University                    | #   # ##### #     ####         |
| Little Rock, AR  72204-1099  USA      | #   # #   # #     #  #         |
| (501)569-8714                         |  ###  #   # ##### #   #        |
| DOMILLER@UALR.BITNET                  | Disclaimer: This does not      |
| 92-20-28 W,34-43-30 N.ICBMNET         | say what I say it doesn't say. |
--------------------------------------------------------------------------

