Hi All,
my requirement send a mail with attachment a abc.txt file.
below is the shell script.
#!/usr/bin/ksh
set -x
#DIR=/appldata/download/mail
MAILTO="krupa.behera@kk.com"
SUBJECT="Report"
BODY="Hi All,"
ATTACH=/projects/psoft/hrdw/pushreports/crons/temp_out
#ATTACH1="$DIR/ahmed1.csv"
(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-bon"'
echo
echo '---BON'
echo "Content-Type: text/plain"
echo "Content-Disposition: inline"
cat $BODY
echo '---BON'
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode $ATTACH $(basename $ATTACH)
echo '---BON--'
) | /usr/lib/sendmail $MAILTO -t -i
i am getting mail body every thing is my exception but not mail Attachment.
Please some one correct this code or give some suggestion how to do it.
Thanks,
Krupa
Yoda
October 18, 2012, 11:15am
2
Try this:-
#!/usr/bin/ksh
set -x
#DIR=/appldata/download/mail
MAILTO="krupa.behera@kk.com"
SUBJECT="Report"
BODY="Hi All,"
ATTACH=/projects/psoft/hrdw/pushreports/crons/temp_out
(
echo "To: $MAILTO"
echo "MIME-Version: 1.0"
echo "Subject: $SUBJECT"
echo 'Content-Type: multipart/mixed; boundary="-bon"'
echo "---bon"
echo "Content-Type: text/plain"
echo "Content-Disposition: inline"
echo '---bon'
echo "$BODY"
echo '---bon'
echo 'Content-Type: text/plain; charset=US-ASCII; name="'$(basename $ATTACH)'"'
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo '---bon'
cat ${ATTACH}
echo '---bon'
) | /usr/lib/sendmail $MAILTO -t -i
Thanks alot, it is working fine but i need some information like i am getting two files with mail one is txt with blank file and another is temp_out.
dout---
what is the meaning of
1.echo 'Content-Type: multipart/mixed; boundary="-bon"'
2.echo "Content-Type: text/plain"
echo "Content-Disposition: inline"
3.echo 'Content-Type: text/plain; charset=US-ASCII; name="'$(basename $ATTACH)'"'
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
i am requesting please explain above lines .
i will be thank full to you.
Thanks,
Krupa
Yoda
October 19, 2012, 12:26pm
4
For fixing the issue with blank attachment. Please perform the following modification:-
/usr/lib/sendmail $MAILTO -t -i
to
/usr/lib/sendmail -t
You can refer to RFC2045 for more information on MIME.
No,still i am getting two files like temp_out.txt with data (it excepted) and another ATT00001.txt with zero byte file (it is not excepted).
i have to run this shell script by weekly(meaning alternative weekly,ex- 2nd week of each month)
how to write a program to check 2nd week of a month.
it is very useful script will be for me.
Thanks,
Krupa
Yoda
October 22, 2012, 11:36am
6
I tested the script with the modification that I suggested and it generated an email without a second attachment (blank). The email address is not required as an argument for sendmail because we already mentioned it in the mail header:- echo "To: $MAILTO".
For scheduling the script you can use cron.