# Sending a file as an attachment to email

**URL:** <https://community.unix.com/t/sending-a-file-as-an-attachment-to-email/322372>\
**Category:** Shell Programming and Scripting\
**Created:** [January 9, 2013, 12:16am UTC](https://community.unix.com/t/sending-a-file-as-an-attachment-to-email/322372 "2013-01-09T00:16:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skatpally](https://community.unix.com/letter_avatar/skatpally/32/5_5575768a8748004e209b776fc1b2916d.png) [@skatpally](https://community.unix.com/u/skatpally)\
**Post date:** [January 9, 2013, 12:16am UTC](https://community.unix.com/t/sending-a-file-as-an-attachment-to-email/322372/1 "2013-01-09T00:16:14Z")

</div>

The file is located under appl/batchdata/  
file name: storesales.txt  
I am using following code because uuencode is not present. I am not getting the data in file but i am getting the blank file with same name as an email attachment.

```nohighlight
( echo "from: sch@xxxx.com"
  echo "to:sch@xxxx.com"
  echo "subject:Store Sales Feed Commission Report for $TODAYDATE"
  echo "mime-version: 1.0"
  echo "content-type: multipart/related; boundary=xxxRANDOMSTRINGxxx"
  echo
  echo "--xxxRANDOMSTRINGxxx"
  echo "content-type: text/plain"
  echo
  echo "Store Sales Feed for the previous day is listed below:"
  echo
  echo "--xxxRANDOMSTRINGxxx"
cd /appl/batchdata/outgoing/commission/dev/
  echo "content-type: text; name=storesales.txt"
  echo "content-transfer-encoding: base64"
  echo
  openssl base64 <mail.success ) | /usr/lib/sendmail -t -i "sch@xxxx.com"

```

---

<div class="post-metadata">

**Author:** ![DGPickett](https://community.unix.com/letter_avatar/dgpickett/32/5_5575768a8748004e209b776fc1b2916d.png) [@DGPickett](https://community.unix.com/u/DGPickett)\
**Post date:** [January 10, 2013, 5:00pm UTC](https://community.unix.com/t/sending-a-file-as-an-attachment-to-email/322372/2 "2013-01-10T17:00:42Z")

</div>

As I recall, you need a mime divider after the base 64 to satisfy that layer. Mime can frame unencoded files, too, 3/4 the length.

---

<div class="post-metadata">

**Author:** ![Yoda](https://community.unix.com/user_avatar/community.unix.com/yoda/32/2498_2.png) [@Yoda](https://community.unix.com/u/Yoda)\
**Post date:** [January 10, 2013, 5:25pm UTC](https://community.unix.com/t/sending-a-file-as-an-attachment-to-email/322372/3 "2013-01-10T17:25:21Z")

</div>

Try this code if you want to send file: `storesales.txt` as attachment:

```nohighlight
{
        echo "From: sch@xxxx.com"
        echo "To: sch@xxxx.com"
        echo "MIME-Version: 1.0"
        echo "Subject: Store Sales Feed Commission Report for $TODAYDATE"
        echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
        echo "---q1w2e3r4t5"

        echo "Content-Type: text/plain"
        echo "Content-Disposition: inline"
        echo '---q1w2e3r4t5'
        echo "Store Sales Feed for the previous day is listed below:"
        echo '---q1w2e3r4t5'

        cd /appl/batchdata/outgoing/commission/dev/

        echo "Content-Type: text/plain; charset=US-ASCII; name=storesales.txt"
        echo "Content-Disposition: attachment; filename=storesales.txt"
        echo '---q1w2e3r4t5'
        cat storesales.txt
        echo '---q1w2e3r4t5--'
} | /usr/lib/sendmail -t

```
