send attachments using send mail in Solaris

Hi All,

I have a requirement to send and email of body html with an attachment.

concatinating uuencode output to the mail body with mailx command works, but as my Email body is of HTML type i use sendmail.

my command to send HTML body is as below:

export MAILTO="recipient@domain.com"
export CONTENT="./html/body.html"
export SUBJECT="TEST EMAIL: TESTING HTML"
(
echo "From: noreply@domain.com"
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Charset: iso-8859-1"
echo "Content-Disposition: inline"
cat $CONTENT
) | /usr/sbin/sendmail -t

With the above command I can send html body contents through send mail.
But, to the above scenario I need even the attachment.

Please help me out for this.

Thanks,
Mohan Kumar CS

If I understand correctly you want to get the content of the file in the email as well as an attachment of the file itself? If so, I used code that Pederabo has written for this and modified it for my use. This will show the content of the file in the email as well as attach the file itself with the email.

export MAILTO="recipient@domain.com"
export CONTENT="./html/body.html"
export SUBJECT="TEST EMAIL: TESTING HTML"

BOUNDARY='=== This is the boundary between parts of the message. ==='

{
print -  "From: Someone <$MAILFROM>"
print -  "To: Someone <${MAILTO}>"
print -  'Subject:' $SUBJECT
print -  'MIME-Version: 1.0'
print -  'Content-Type: MULTIPART/MIXED; '
print -  '    BOUNDARY='\"$BOUNDARY\"
print -
print -  '        This message is in MIME format.  But if you can see this,'
print -  "        you aren't using a MIME aware mail program.  You shouldn't "
print -  '        have too many problems because this message is entirely in'
print -  '        ASCII and is designed to be somewhat readable with old '
print -  '        mail software.'
print -
print -  "--${BOUNDARY}"
print -  'Content-Type: TEXT/PLAIN; charset=US-ASCII'
print -
cat $CONTENT
print -
print -
print -  "--${BOUNDARY}"
print -  'Content-Type: TEXT/PLAIN; charset=US-ASCII; name='${CONTENT}
print -  'Content-Disposition: attachment;   filename='${CONTENT}
print -
cat ${CONTENT}
print -
print -  "--${BOUNDARY}--"
} | /usr/sbin/sendmail ${MAILTO}

In order to get the attachment name without the directory included (set by variable CONTENT), cd to your 'html' directory then send the attachment without specifying the fullpath to the filename.