Operating System - OpenVMS
1748202 Members
3043 Online
108759 Solutions
New Discussion

Re: How to create a batch file to send email?

 
SOLVED
Go to solution
WilliamGoGo
Occasional Contributor

How to create a batch file to send email?

I knew send email in VMS is: $mail

send ...

but, how to put those commands into com file of OpenVMS ?

Any suggest?

Thanks,

6 REPLIES 6
Volker Halle
Honored Contributor

Re: How to create a batch file to send email?

William,

 

you can send mail with one DCL command (see $ HELP MAIL EXAMPLES) like this:

 

$ MAIL/SUBJECT="..." filename "user@domain"

 

If you use SYS$INPUT instead of filename, you can put your mail text body into a DCL procedure immediately following the above command.

 

You can also include mail commands in a DCL procedure like this:

 

$ MAIL

SEND/NOEDIT

user@domain

This is the subject line

Then follows the body of the mail message,

$ EXIT

 

Volker.

 

WilliamGoGo
Occasional Contributor

Re: How to create a batch file to send email?

Thanks, it's working, but I had one more question:

 

how to put variable into email title, such as:

 

$ val

$mail

send

no@email.com

the value is $val

$exit

 

it does not working.

 

Thanks again,

Volker Halle
Honored Contributor
Solution

Re: How to create a batch file to send email?

William,

 

it's not possible to put a variable name into an input stream read from the DCL command file itself and expect that variable name to be substituted with the current value of the variable.

 

Instead, you can use the one-line MAIL command, which allows you to specify the /SUBJECT string including variables (e.g. /SUBJ="text including ''val' ...", which get substituted or you can create a short DCL procedure file on-the-fly with the necessary values hard-coded,like:

 

$ OPEN/WRITE x mail.tmp

$ WRITE x "$ mail"

$ WRITE x "send"

$ WRITE x "no@email.com"

$ WRITE x "the value is ''val'"

$ WRITE x "$ EXIT"

$ CLOSE x

$ @X

$ DELETE/NOLOG/NOCONF mail.tmp;0

 

Volker.

H.Becker
Honored Contributor

Re: How to create a batch file to send email?

It looks like you compared the DCL input stream with a Unix  Here Document. As already said, DCL doesn't do variable expansion but Here Documents do.

 

If you have GNV installed, you can use its bash and then you can use the variable expansion. But if you have a DCL symbol (variable) then you need to set a corresponding variable to the symbol's value in the bash. That seems a lot more overhead than just writing a temporary file. Anyway, just for fun, with GNV/bash you can do:
 
bash$ dcl "mail/subj=\"from $SHELL\" sys\$input becker_h" <<end
> from $HOME
> end
New mail on node NODE from NODE::BECKER_H     "H Becker"
bash$ exit
$ mail
You have 1 new message.
MAIL> 1
    #1          27-DEC-2011 03:52:31.38                                  NEWMAIL
From:   NODE::BECKER_H     "H Becker"
To:     BECKER_H
CC:
Subj:   from bash
from /disk_user/decuserve_user/becker_h
MAIL>
WilliamGoGo
Occasional Contributor

Re: How to create a batch file to send email?

Volker,

 

Very appreciated.

John Gillings
Honored Contributor

Re: How to create a batch file to send email?

You can use PIPE to get variables into MAIL messages without the need for temporary files.

 

$ OUT="WRITE SYS$OUTPUT"

$ Subj="Your Subject"

$ To="your@recipient.com"

$ var="Some text"

$ count=5

$ PIPE ( -

  OUT "This is the body of the message" ; -

  OUT "which may contain variables ''var'" ; -

  OUT "or expressions ",count+1 ) | -

  MAIL/SUBJECT="''Subj'" SYS$PIPE "''to'" > nl:

 

The trailing "> nl:" sends the "Enter your message below" prompt to the null device.

 

A crucible of informative mistakes