Wednesday, October 22, 2008

How to send email with attachments using mailx utility?

Here is a code stolen from orafaq.com that helps to send email with attachments using mailx utility (with slight modifications, ofcourse)
#!/bin/ksh
# -----------------------------------------------------------------------
# Filename: mailx.ksh
# Purpose: Demonstrates how one can attach files when sending E-Mail
# messages from the Unix mailx utility.
# Author: Frank Naude, Oracle FAQ
# -----------------------------------------------------------------------
SUBJECT="Send mail from Unix with file attachments"
TO="address1@domain.com address2@domain"
echo "Send the E-mail message..."
/usr/bin/mailx -s "$SUBJECT" "$TO" <<-EOF
Hi,
This sample E-mail message demonstrates how one can attach files when sending messages with the Unix mailx utility.

First attachment: mailx.ksh (this script)
Second attachment: /etc/passwd file

Best regards
your name

~< ! uuencode mailx.ksh mailx.txt
~< ! uuencode /etc/passwd passwords
~.
EOF
echo "Done!"

No comments: