Wednesday, March 23, 2011

How can I script the body of a VMS mail?

I have a script that addresses and sends an email but I need a body in the message without creating a file and then inserting the file with the standard MAIL commandline.

How can I do that?

From stackoverflow
  • Have the script create a temporary file to hold the body of the message.

    Mail will accept a text file on the command line, like the list of users and the /subj

  • Assuming the body you want to create is something you can write to SYS$OUTPUT (e.g. the output of a command procedure or DCL command), then you can use DCL PIPE to pipe the output into VMS Mail, like:

    $ PIPE write sys$output "The date is ", f$cvtime() | MAIL SYS$INPUT smith/SUBJ="Piping in DCL"
    

    or

    $ PIPE DIR *.LOG | MAIL SYS$INPUT smith/SUBJ="Piping in DCL"
    

    The PIPE command was added in OpenVMS V7.1. If you are somehow on an pre-7.1 system, then your only choice is writing to a temporary file and cleaning up.

    Edit: To answer the comment, if you want to eliminate the interactive displays from the Mail command, you can redirect SYS$OUTPUT to NLA0:, as in:

    $ PIPE DIR *.LOG |  MAIL SYS$INPUT smith/SUBJ="Piping in DCL" > NLA0:
    

    Error messages go to SYS$ERROR, so you'll still see any failures. See HELP PIPE for more goodness.

    Keng : Awesome. thanks! any way for it not to print "Enter your message below. Press CTRL/Z when complete, or CTRL/C to quit:" on the commandline when you run it?

0 comments:

Post a Comment