Sponsored Content
Top Forums Shell Programming and Scripting How to attach two files in unix script Post 302478888 by meva on Thursday 9th of December 2010 06:42:55 AM
Old 12-09-2010
Hi,

For my requirement i wrote a separate script for sending email
Code:
#! /usr/bin/ksh
function sendEmail
{
MAILTO=$1
SUBJECT=$2
BODY=$3
export ATTACH=$4
export ATTACH1=$5
echo $BODY
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/plain"
 echo "Content-Disposition: inline"
 echo $BODY 
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode -m $ATTACH "output.txt"
 echo '---q1w2e3r4t5--'
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH1)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH1)'"'
 uuencode -m $ATTACH1 "output.txt"
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO
}

and for sending email i called the below command
Code:
sendEmail $EMAILLIST "$SUBJECT" "Hello" "$File1" "$File2"

But am able to view only one attachment how can i modify the code to get 2 attachments attached?

Kindly help me with your thoughts.

Thanks In Advance.
Meva.

---------- Post updated at 06:32 AM ---------- Previous update was at 06:14 AM ----------

Hey..... My script is working now Smilie i made changes to it and my final script is given below
Code:
#! /usr/bin/ksh
function sendEmail
{
MAILTO=$1
SUBJECT=$2
BODY=$3
export ATTACH=$4
export ATTACH1=$5
echo $BODY
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/plain"
 echo "Content-Disposition: inline"
 echo $BODY 
 echo '---q1w2e3r4t5'
 echo 'Content-Type: TEXT/PLAIN; charset=US-ASCII; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode -m $ATTACH "output.txt"
 echo '---q1w2e3r4t5'
 echo 'Content-Type: TEXT/PLAIN; charset=US-ASCII; name="'$(basename $ATTACH1)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH1)'"'
 uuencode -m $ATTACH1 "output1.txt"
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO
}

But the problem i was facing is that i was not able to view the body of the email and its blank in my mail; its getting echoed in the command prompt....how do i include the body content to my email to my mail.....

---------- Post updated at 06:42 AM ---------- Previous update was at 06:32 AM ----------

Hey my script is now working fine now Smilie Below code is used for attaching the .csv files to email

Code:
#! /usr/bin/ksh
function sendEmail
{
MAILTO=$1
SUBJECT=$2
BODY=$3
export ATTACH=$4
export ATTACH1=$5
echo $BODY
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/plain"
 echo "Content-Disposition: inline"
 echo 
 echo $BODY 
 echo
 echo '---q1w2e3r4t5'
 echo 'Content-Type: TEXT/PLAIN; charset=US-ASCII; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode -m $ATTACH "output.txt"
 echo '---q1w2e3r4t5'
 echo 'Content-Type: TEXT/PLAIN; charset=US-ASCII; name="'$(basename $ATTACH1)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH1)'"'
 uuencode -m $ATTACH1 "output1.txt"
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO
}

Then i called the below command and it worked

Code:
sendEmail $EMAILLIST "$SUBJECT" "Hello" "$File1" "$File2"

Thanks All for your valuable inputs Smilie

Meva.
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

pine does'nt attach files

Hello All, I am maintaining a server and I use pine as MUA and sendmail as MTA. Suddenly many users in the network face the problem of not being able to attach files using pine. I checked the sendmail.cf file and found a variable "MaxMessageSize = 1000000". Eventhough the message size... (2 Replies)
Discussion started by: maybemedic
2 Replies

2. Shell Programming and Scripting

attach 2 files using mailx

if test.dat is the file cat test.dat|uuencode test.dat|mailx -s "subject" mailid can be used for attaching test.dat how can i attach more than one file to a mail using mailx (2 Replies)
Discussion started by: anumkoshy
2 Replies

3. Shell Programming and Scripting

attach multiple files in email

I am trying to send multiple files as attachment in one email, I tried to search but couldn't find. Please let me know if any solutions. (2 Replies)
Discussion started by: mgirinath
2 Replies

4. Shell Programming and Scripting

Attach a binary file to email in a script

Hi, I am trying to get an email sent out by the unix ( aix ) system that has a .gz file attached to it. I can get the attachment, but it's not working when being looked at from outlook. I think there is a problem because of the way I am doing it, and the fact that it's binary. I am trying to... (15 Replies)
Discussion started by: fwellers
15 Replies

5. Shell Programming and Scripting

Script to attach file to mail

Hello, I have a .dat file containing one line. I need a script to read that line and make it part of the body and send a mail... Let's say the line is $line. I need the script to send a mail with the body "The last disposal feed is $line". Thanks (4 Replies)
Discussion started by: sfetea
4 Replies

6. Shell Programming and Scripting

How to attach multiple .csv files using mutt command

I need to attach all files starting with 'BusinessReport' using mutt command. It could be any number of files in that directory, say BusinessReport_01, BusinessReport_03, BusinessReport_04 etc. Is there a way to attach all files where filename like BusinessReport_* and sent it using mutt... (2 Replies)
Discussion started by: Jassz
2 Replies

7. Shell Programming and Scripting

UNIX - how to send attach excel in mail

Hi Experts, i need your help here :confused: Need to send a report thru mail using unix shell script(AIX). can you help me to do this? . i tried "uuencode" with CSV format, but while reading report all values are in single column. i need each column values in separate cell. Thanks in... (9 Replies)
Discussion started by: newbieabc
9 Replies

8. Shell Programming and Scripting

Script to attach latest files of directories in a mail.

Hello Folks, I am looking for the script which will go to directory and check for the latest 5 files and send a mail to attaches these files to user. Kindly guide. Regards (7 Replies)
Discussion started by: sadique.manzar
7 Replies

9. Shell Programming and Scripting

Attach filename to wc results on massive number of files

Hello, I have massive number of big files that needed to be counted for the total number of lines (> 100x millions) each. I want the file name attached to the count results so that they are aligned nicely matching name and counts. I could do each file at a time, which will take hours to finish,... (8 Replies)
Discussion started by: yifangt
8 Replies
All times are GMT -4. The time now is 07:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy