Getting mail with no Attachment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting mail with no Attachment
# 1  
Old 10-18-2012
Getting mail with no Attachment

Hi All,

my requirement send a mail with attachment a abc.txt file.
below is the shell script.
Code:
#!/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

Last edited by Franklin52; 10-18-2012 at 09:45 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 10-18-2012
Try this:-

Code:
#!/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

# 3  
Old 10-19-2012
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
# 4  
Old 10-19-2012
For fixing the issue with blank attachment. Please perform the following modification:-

Code:
/usr/lib/sendmail $MAILTO -t -i

to
Code:
/usr/lib/sendmail -t

You can refer to RFC2045 for more information on MIME.

Last edited by Yoda; 10-19-2012 at 01:42 PM..
# 5  
Old 10-22-2012
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
# 6  
Old 10-22-2012
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mail attachment

Hi, I want to send an attachment and content in a single mail using unix command can anyone pls help me? Thanks Naveen A (6 Replies)
Discussion started by: Pranaveen
6 Replies

2. Shell Programming and Scripting

Mail Attachment...

Hi All, I am new to unix. I have written the script to identify the delimiter count for my source file and the output I have to capture in another file and that file should sent to mail with attachment. I have tried to send the attachment with below script . But I am not able to do that. Any... (2 Replies)
Discussion started by: suresh_target
2 Replies

3. Shell Programming and Scripting

Send mail using attachment

Hi All, I need to send mail with attachment. I am using uuencode but it seems it is sending encoded file. I am getting the mail with attachment but there is no data even the file size is almost 90KB. Please help. Thanks. (3 Replies)
Discussion started by: unankix
3 Replies

4. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

5. Shell Programming and Scripting

How to send a mail with attachment?

Hi, I usually write a file TEST.MAIL like this to send mails: Importance: High Priority: Urgent X-Priority: 1 (Highest) From: user Subject: error ... text body .... and then I launch it (or writre a c-chell that launchs it) by writing: mail a@b.com < /users/.../TEST.MAIL How can... (4 Replies)
Discussion started by: albaalbetti
4 Replies

6. Shell Programming and Scripting

Mail attachment with unix mail

Hi Could someone help me with the details on how to send an attachment through mail in unix. I have an html file in my unix machine and I want this to be send to some mail id, plese help with the steps. Regards Ajay (2 Replies)
Discussion started by: ajaykumarboyana
2 Replies

7. UNIX for Advanced & Expert Users

mailx commannd - Mail and Attachment in same mail

Hi , I am using mailx command for sending the mails. Rightnow I am sending the attachment (by using uuencode $filename) as a seperate mail.I wanna send the attachment also with the same mail. (6 Replies)
Discussion started by: sharif
6 Replies

8. Shell Programming and Scripting

mail with attachment

Hi, I am facing an issue while sending a mail from unix with attachment.the issue is i am able to send a mail with attachment but...after receiving the mail if u see that the text is continous though it was line by line in original.. UUENCODE is the cmd i am using... plz help me in this... (1 Reply)
Discussion started by: param786
1 Replies

9. UNIX for Dummies Questions & Answers

mail attachment

This question has been asked many time before. I did search other questions. But was not able to work out. Really sorry for repeating the same question. I have mail and mailx and sendmail installed. It Tried this uuencode FILENAME.txt FILENAME.txt | mail mymail@yahoo.com the attachment... (3 Replies)
Discussion started by: sushrut
3 Replies
Login or Register to Ask a Question