Sending Attachment using MIME in UNIX

Hi,

I am using the below code for sending attachment in UNIX but only blank attachment is coming in email even the content is not coming.

Please help!!!

export CONTENT="${DIR}/${RUN_DATE}_mailbody.txt"
export SUBJECT="Search Result for Pattern - ${1}"
export ATTACH=${2}
(
echo "Content-Transfer-Encoding: 7bit"
echo "Content-Type: multipart/mixed; boundary=_----------=_10167391557129230"
echo "MIME-Version: 1.0"
echo "To: ${EMAIL_ADR}"
echo "Subject: ${SUBJECT}"
echo "--_----------=_10167391557129230"
echo "Content-Type: text/html"
echo "Content-Transfer-Encoding: binary"
echo "Content-Disposition: inline"
cat ${CONTENT}
echo "--_----------=_10167391557129230"
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Type: application/text; name=$ATTACH"
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo "Content-Disposition: attachment; filename=$ATTACH"
echo "--_----------=_10167391557129230--"
echo "."

Thanks,
Rajesh

is there some reason not to use uuencode?

uuencode ${2} ${2} | /usr/bin/mailx -s "$SUBJECT" < $CONTENT

Hi,

I need the email in HTML format that's why I am using MIME.

Thanks,
Rajesh

Hard to follow from the script posted whether you want the html to appear in the message body or in as an attachment.
Also it would help to see examples of the data and the command used to invoke the script.

If you need an attachment, maybe try jim mcnamara's post with an attachment filename ending in ".htm" and leave the hard work to the mail client.

I want the message body in HTML format and the attachment as it is.

Thank you for the examples.

Does this shell script even work? There are no spaces between echo and the string to be echoed, e.g.

echo"MIME-Version:1.0"

Oops. I made a bit of a mess of reformatting the post when adding code-tags.

The original had spaces (lots of spaces!).

Well spotted :slight_smile:

There is a space and the script is working fine. In the email I am only getting blank attachment without any content

You need a blank line after the boundary line, and after the content-type line.
You can also use "mutt" and save a lot of grief. mutt.org