`

Unix Shell--Using mailx

阅读更多

Syntax

mailx [-B] [-d] [-e] [-F] [-H] [-i] [-I] [-n] [-N] [-U] [-R] [-t] [-v] [-V] [-~] [-b bcc] [-c cc] [-h number][ -f [file | +folder ] ] [ -T file ] [ -u user ] [-s subject] Recipients 

-B Do not buffer standard input or standard output.
-d Turn on debugging output. (Neither particularly interesting nor recommended.)
-e Test for the presence of mail. mailx prints nothing and exits with a successful return code if there is mail to read.
-F Record the message in a file named after the first recipient. Overrides the record variable, if set.
-H Print header summary only.
-i Ignore interrupts.
-I Include the newsgroup and article-id header lines when printing mail messages. This option requires the -f option to be specified.
-m  
-n Do not initialize from the system default mailx.rc or Mail.rc file.
-N Do not print initial header summary.
-U Convert UUCP-style addresses to Internet standards. Overrides the conv environment variable.
-R  
-t Scan the input for To:, Cc:, and Bcc: fields. Any recipients on the command line will be ignored.
-v Pass the -v flag to sendmail.
-V Print the mailx version number and exit.
-~ Interpret tilde escapes in the input even if not reading from a tty.
-b bcc Set the blind carbon copy list to bcc. bcc should be enclosed in quotes if it contains more than one name.
-c cc Set the carbon copy list to cc. cc should be enclosed in quotes if it contains more than one name.
-h number The number of network "hops" made so far. This is provided for network software to avoid infinite delivery loops. This option and its argument are passed to the delivery program.
-r address Use address as the return address when invoking the delivery program. All tilde commands are disabled. This option and its argument is passed to the delivery program.
-s subject Set the Subject header field to subject. subject should be enclosed in quotes if it contains embedded white space.
recipient The recipient of the e-mail.
-f [file] Read messages from file instead of mailbox. If no file is specified, the mbox is used.
-f [+folder] Use the file folder in the folder directory (same as the fold er command). The name of this directory is listed in the folder variable.
-T file Message-id and article-id header lines are recorded in file after the message is read. This
option also sets the -I option.
-u user Read user's mailbox. This is only effective if user's mailbox is not read protected.


# Example 1 - Simple:
echo "This is the body."| mailx -s "mailx Test1" jsmith@abc.com


# Example 2 - Using Variables:
SUBJECT="mailx Test2"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."

echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"


# Example 3 - Attached File:
SUBJECT="mailx Test3"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
ATTACHED_FILE="/etc/hosts"

cat "$ATTACHED_FILE" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"


# Example 4 - Attached File to Windows Email:
SUBJECT="mailx Test4"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
ATTACHED_FILE_DIR="/etc/"
ATTACHED_FILE="hosts"
ATTACHED_FILE_AS="hosts.txt"

unix2dos "$ATTACHED_FILE_DIR$ATTACHED_FILE" > /tmp/"$ATTACHED_FILE_AS"
uuencode /tmp/"$ATTACHED_FILE_AS" /tmp/"$ATTACHED_FILE_AS" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
rm /tmp/"$ATTACHED_FILE_AS"

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics