Operating System - HP-UX
1753418 Members
4696 Online
108793 Solutions
New Discussion юеВ

Re: Send multiple attachments with sendmail

 
PM Srividhya
Advisor

Send multiple attachments with sendmail

Hi,

I want to send multiple attachments from the sendmail utility (or any other e-mail utility in HP-UX).

I'm able to attach one file with the following script:

#! /usr/bin/ksh
# Arguments : -f -t -c -s -b -a

#For Eg. sendMail -t user@host.com -c user1@host1.com -s subject -b body -a attach.txt


while getopts 'f:t:c:s:b:a:' opt
do
case $opt in
f)
fromAddress=$OPTARG
;;
t)
toAddress=$OPTARG
;;
c)
ccAddress=$OPTARG
;;
s)
subject=$OPTARG
;;
b)
body=$OPTARG
;;
a)
attachment=$OPTARG
;;
:)
print "$OPTARG need an argument"
exit 1
;;
\?)
print "$OPTARG need a value"
exit 1
;;
esac
done

if [ -z "$toAddress" ] || [ -z "$subject" ] || [ -z "$body" ] || [ -z "$attachment" ]
then
print "Error: To Address, Subject and Body of the mail and attachment are required arguments"
exit 1
fi
if [ ! -f $attachment ] || [ ! -r $attachment ]
then
print "$attachment is not a readable file"
exit 1
fi

boundary='=== This is the boundary between parts of the message. ==='
{
print - "From: <${fromAddress}>"
print - "To: <${toAddress}>"
print - "Cc: <${ccAddress}>"
if [ -n $subject ]
then
print - 'Subject:' $subject
fi
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - ' BOUNDARY='\"$boundary\"
print -
print -
print - "--${boundary}"
print - 'Content-Type: TEXT/PLAIN; charset=US-ASCII'
print -
cat $body
print -
print -
print - "--${boundary}"
print - 'Content-Type: TEXT/PLAIN; charset=US-ASCII; name='$attachment
print - 'Content-Disposition: attachment; filename='$attachment
print -
cat $attachment
print -
print - "--${boundary}--"
} | /usr/lib/sendmail "${toAddress} ${ccAddress}"

Could any body please help me how to do it for multiple attachments?

Thanks,
Vidhya
6 REPLIES 6
Peter Godron
Honored Contributor

Re: Send multiple attachments with sendmail

Court Campbell
Honored Contributor

Re: Send multiple attachments with sendmail

tarball all the attachments, then use uuencode.

uuencode tarball tarball | mailx -s "subject" to@me.org
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Arturo Galbiati
Esteemed Contributor

Re: Send multiple attachments with sendmail

Hi,
by mail:

mail -t <Subject: test
From:
Cc:
bcc:
$(ux2dos test.txt|uuencode test.txt)
$(ux2dos test.html|uuencode test.html)
EOF

HTH,
Art

N.B. Please remeber to assign points
Dave La Mar
Honored Contributor

Re: Send multiple attachments with sendmail

Vidhya -
You have many fine examples here. Allow me to ads an additional set of examples in the attached.

Regards,
-dl
"I'm not dumb. I just have a command of thoroughly useless information."
PM Srividhya
Advisor

Re: Send multiple attachments with sendmail

Thanks all for the replies. I'm using the one suggested by Art to use uuencode along with mail and it works the way i'm looking for.
Thanks Art... (I should have given more points to you :O))
PM Srividhya
Advisor

Re: Send multiple attachments with sendmail

Thanks for all replies.