Wednesday, February 06, 2008

Simple ksh script to sent a mail using SMTP server.

This script can send mail using SMTP server. However limitation is that, SMTP server should be open for all. i.e NO authentication support.

You can change the data fields as you like, but not the order of execution. (This is strict as the script is supplying arguements for the SMTP protocol which is not very flexible. If you add space in the Keywords, it may not work.) In other words, you can only change the fields marked bold italic

#!/usr/bin/ksh
MAILADDR=user@recipient.com
TEMPFILE=/your/data/file

(sleep 5
echo EHLO
sleep 5
echo MAIL FROM: user@yourdomain.com
sleep 5
echo RCPT TO: $MAILADDR
sleep 5
echo DATA
sleep 5
echo From: user@yourdomain.com
echo To: $MAILADDR
echo subject: Daily report
echo
echo “”
cat $TEMPFILE
echo “”
echo
sleep 5
echo .
sleep 5
echo QUIT
sleep 5) | telnet www.mailserver.com 25

You may be interested to take a look at unix related links

No comments: