	SUBROUTINE OPENMAIL(mail_node, local_node, open_write, opened)
	IMPLICIT INTEGER(A-Z)
	INTEGER*4 str$trim, mail_len, icode, ios
	CHARACTER mail_node*31, local_node*31, mail_file*31, open_mode*4
	LOGICAL opened
	EXTERNAL netmail_mailfile, netmail_upderr
	EXTERNAL netmail_decnet
C
C	Set strings.
C
	mail_file = ' '
	opened = .false.
C
C	Set up mail_file name (node::SYS$SYSTEM:VMSMAIL.DAT).
C
	If (mail_node.ne.local_node) then
	icode = STR$TRIM(mail_node, mail_node, mail_len)
	mail_file = mail_node(1:mail_len) // 'SYS$SYSTEM:'
	CALL LIB$SIGNAL(netmail_decnet,%val(1), mail_node(1:mail_len-2))
	 Else
	 mail_file = 'SYS$SYSTEM:'
	Endif !Mail_file name declaration.
	icode = STR$TRIM(mail_file, mail_file, mail_len)
C
C	Open the mail file. If error, set flag.
C
	If (.not.open_write) then  !open it for READONLY.
	open(unit=1, file='VMSMAIL.DAT', err=100,
     +  status='OLD', READONLY, SHARED,
     +  access='KEYED', iostat=ios,
     +  organization='INDEXED',
     +  form='UNFORMATTED',
     +  recordtype='VARIABLE',
     +  recl=177, defaultfile=mail_file(1:mail_len),
     +  key=(1:31:character))
C
	Else !Open it for write.
C
	open(unit=1, file='VMSMAIL.DAT', err=100,
     +  status='OLD', SHARED,
     +  access='KEYED', iostat=ios,
     +  organization='INDEXED',
     +  form='UNFORMATTED',
     +  recordtype='VARIABLE',
     +  recl=177, defaultfile=mail_file(1:mail_len),
     +  key=(1:31:character))
	Endif !Open file.
C
C	File opened successfully.
C
	opened = .true.
	return
C
C	File not opened! ERROR.
C
100	continue
	opened = .false.
	icode = STR$TRIM(mail_node, mail_node, mail_len)
	CALL LIB$SIGNAL(netmail_mailfile,%val(1),mail_node(1:mail_len-2))
	if (open_write) CALL LIB$SIGNAL(netmail_upderr)
	return
C
	end
