Send attachment through sendmail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Send attachment through sendmail
# 1  
Old 04-15-2014
Send attachment through sendmail

Hi,

I am trying to send log file of a job run in unix machince through sendmail.Though I am able to send the text but it is not sending as attachment.

Could you please look into the code and let me know where I have gone wrong
Code:
fdate=`date %Y%j`
file_wc="/global/spsnfs/home/oracle2/sps2arc/test/*_${fdate}.txt"
attachments=''
for f in `ls ${file_wc}`; do
attachments="$attachments
 
Content-Type: text/plain;
Content-Disposition: attachment; filename=`basename $f`


Last edited by vbe; 04-15-2014 at 12:43 PM.. Reason: code tags - not HTML, thank you
# 2  
Old 04-15-2014
Your code is over-complex for a start. You don't need the `ls ${file_wc}` bit at all. Just use for f in ${file_wc}

You also have a missing " for the attachments= statement.

I don't see where you are trying to use sendmail either. The code sort of peters out and then gets lost after that.

Can you confirm that this is the correct code?



Robin
# 3  
Old 04-15-2014
Hi,
Thanks for the reply.here is the complete code, i am tryng to get the attachment in the email which it is not sending
HTML Code:
fdate=`date %Y%j`
file_wc="/global/test/*_${fdate}.txt"
boundary='=== MESSAGE ==='
attachments=''
for f in `ls ${file_wc}`; do
attachments="$attachments
--${boundary}
Content-Type: text/plain;
Content-Disposition: attachment; filename=`basename $f`

`cat $f`

"
done

message="<html>
<body>
<p> Attached are the
log files for the various types of data which was archived. Please review the
logs for any errors and take the appropriate action</p>
</body>
</html>"

cat <<EOM | /usr/lib/sendmail -t
To:  EMAIL IDS
Subject: Archival complete
MIME-Version: 1.0
Content-Type: MULTIPART/MIXED;
    BOUNDARY="${boundary}"

--${boundary}
Content-Type: text/html;

${message}

${attachments}

--${boundary}--
EOM

#TAR and compress logs
files=''
for f in `ls ${file_wc}`; do
  files="$files $f"
done
$v_tar -cPjf /global/archive_${date}.tbz ${files}
if [ "$?" -eq "0" ]; then
  rm -rf ${files}
fi
exit
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with attachment in sendmail

Hi Folks I have below code, which is able to successfully send the content of the output file as html which is body, but i did tried uuencode & mailx -a for sending attachments but to no avail. cat - ${Output_File} <<EOF| /usr/sbin/sendmail -oi -t #From: ${MAILFROM} To: ${MAILTO} Subject:... (5 Replies)
Discussion started by: nikhil jain
5 Replies

2. Shell Programming and Scripting

Sendmail with attachment

Hello people, I only have sendmail and uuencode on a Oracle (RH) linux server. While: /usr/bin/uuencode awr.html awr.html | /usr/sbin/sendmail myemail@company.com Is working fine, the ideal for me is to do something like: echo "To: me@company.com" > /home/vasilis/msg.txt echo "Subject: DB... (3 Replies)
Discussion started by: drbiloukos
3 Replies

3. Shell Programming and Scripting

sendmail with attachment not working

dear all I have below function which send an email, but if I need to add an attachement it won't work instead it write some jibberish to body of the email begin 644 SIGN_OFF_AP_20120626.csv M4TE'3E]/1D9?4TA%150L351-7T1!5$4L0D]/2RQ35$%455,L5D%25%E012Q# %3U5.5`H` ` end function... (6 Replies)
Discussion started by: manas_ranjan
6 Replies

4. AIX

How to send attachment using "sendmail" command or without uuencode command

Hi Guys, I dont have uuencode, mutt, base64 command available on my aix machine there is any alternative way to send file as attachement in mail. (1 Reply)
Discussion started by: ns64110
1 Replies

5. Shell Programming and Scripting

How to send attachment using "sendmail" command or without uuencode command

Hi Guys, I dont have uuencode, mutt, base64 command available on my aix machine there is any alternative way to send file as attachement in mail. (3 Replies)
Discussion started by: ns64110
3 Replies

6. Shell Programming and Scripting

sendmail attachment issue

Hi All,, After long time, might be this is nth time post on this forum for the same query...but i tried browsing for sometime and i did not get what i wanted :) i have following syntax in my shell scripting.. (cat filename.txt uuencode attachment attachment)|/usr/lib/sendmail -t... (4 Replies)
Discussion started by: Shahul
4 Replies

7. UNIX for Dummies Questions & Answers

sendmail attachment problem

Hello, i am sending email with following command. The problem is the attachment is displayed as inline text instead of a file attached to email. What should i do? I don't have chance to install new binaries to the server (SunOS) ( \ echo From: Sender ; \ echo Subject: Testing ; \... (1 Reply)
Discussion started by: yakari
1 Replies

8. UNIX for Dummies Questions & Answers

Using Sendmail (& attachment)

Hi, This is my first thread. Iam trying the following: OS: Sun Database: DB2, Informix, Oracle * Get the status of the database (using database command line options) * pipe to a text file * send mail of the text file to receiptents. TODO1: First step i tried to send a test message.... (3 Replies)
Discussion started by: kenkanya
3 Replies

9. Solaris

attachment using sendmail

Hi, I use the sendmail command to send automatic e-mail in my control programs, but I'd like to know if there's a non interactive way to send an attachment, like a small text file through sendmail command. I didn't find a way in the man, so anyone has already done it?.. give an example for the... (4 Replies)
Discussion started by: vastare
4 Replies
Login or Register to Ask a Question