Re: How to create a batch file to send email? (1241 Views)
Reply
Occasional Contributor
Posts: 4
Registered: ‎12-26-2011
Message 1 of 7 (1,350 Views)
Accepted Solution

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,

Honored Contributor
Posts: 5,231
Registered: ‎04-26-2004
Message 2 of 7 (1,348 Views)

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.

 

Occasional Contributor
Posts: 4
Registered: ‎12-26-2011
Message 3 of 7 (1,343 Views)

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,

Honored Contributor
Posts: 5,231
Registered: ‎04-26-2004
Message 4 of 7 (1,340 Views)

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.

Esteemed Contributor
Posts: 378
Registered: ‎04-09-2009
Message 5 of 7 (1,335 Views)

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

[ Edited ]

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>
Occasional Contributor
Posts: 4
Registered: ‎12-26-2011
Message 6 of 7 (1,303 Views)

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

Volker,

 

Very appreciated.

Honored Contributor
Posts: 3,002
Registered: ‎07-31-2003
Message 7 of 7 (1,241 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.