Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I send email from a Sun System (use mailx)?

Administration

How do I send email from a Sun System (use mailx)?

by  Michael42  Posted    (Edited  )
[color green]
#!/bin/sh
#
# Purpose: Demonstrate how to send an email from UNIX using mailx.
############################################################
[/color]

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


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

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


[color green]# Example 3 - Attached File:[/color]
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"


[color green]# Example 4 - Attached File to Windows Email:[/color]
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"
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top