Posts Tagged ‘send email from UNIX’

Send mail bash script

Mail is the command in UNIX bash shell to send email from that machine to one or more recipient. Mail can be invoked with arguments which are the recipients. This is followed by your message and ‘ctrl-D’ at the start of the line. The simple way to send a mail from unix is:

mail -s ‘Mail Subject’

Example Shell Script to send Mail.

Use the below sample shell script:

# Shell script to send email

# Email Subject
SUB=”Email Subject”

# Email Recipient

# Email text/message
echo “Hey – How is it going”> $EMAIL-MESSAGE
echo “Send mail bash Shell script works fine” >>$EMAIL-MESSAGE

# send email using /bin/mail

/bin/mail -s “$SUB” “$EMAIL” < $EMAIL-MESSAGE

Steps for dummies:
Go to the dir you want to have this shell script.
vi (create shell script)
Paste the above code.
:wq (Save the shell)
chmod 755 (Give permission to the script)
./ (Run the script)

1 comment - What do you think?  Posted by admin - March 16, 2011 at 1:48 pm

Categories: Tech Support   Tags: , , , ,