0

I am trying to send attached file with uuencode from shell script this way:

uuencode logq.txt logq.txt |mail -s "DB Capacity" xxxx@000.net

I recieve the file encrypted and not even attached..

e.g -

begin 664 logq.txt
M"E1U92!-87(@,CD@(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @ M(" @(" @(" @(" @(" @(" @(" @(" @(" @<&%G92 @(" Q"B @(" @(" @ M(" @(" @(" @(" @(" @(" @(" @(" @4$U-($1"($-!4$%

Can some one give me an idea how to solved it?

bmk
  • 13,849
  • 5
  • 37
  • 46
shamir chaikin
  • 681
  • 1
  • 6
  • 9
  • 2
    Possible duplicate of [How do I send a file as an email attachment using Linux command line?](https://stackoverflow.com/questions/17359/how-do-i-send-a-file-as-an-email-attachment-using-linux-command-line) – tripleee Nov 18 '18 at 13:24

1 Answers1

1

Please see my answer to this question: How to send HTML body email with multiple text attachments using sendmail on how to send attachments in Unix bash scripts.

EDIT

Based on your latest requirements here is a simple Unix script to send plain text attachment:

FROM=from-email@example.com
TO=to-email@example.com
SUBJECT="PMM DB CAPACITY"
BODY="Hi, This email comes with a text attachment. Thanks!"
TXTFILE="/tti/netrac/integration/scripts/maint_scripts/log.txt log.txt"    
BOUNDARY="=== This is the boundary between parts of the message. ==="
{
   echo  "From: ${FROM}"
   echo  "To: ${TO}"
   echo  "Subject: ${SUBJECT}"
   echo  "MIME-Version: 1.0"
   echo  "Content-Type: MULTIPART/MIXED; "
   echo  "    BOUNDARY="\"${BOUNDARY}\"
   echo
   echo  "        This message is in MIME format.  But if you can see this,"
   echo  "        you aren't using a MIME aware mail program.  You shouldn't "
   echo  "        have too many problems because this message is entirely in"
   echo  "        ASCII and is designed to be readable with old mail software."
   echo
   echo  "--${BOUNDARY}"
   echo  "Content-Type: TEXT/PLAIN; charset=US-ASCII"
   echo
   echo  "${BODY}"
   echo
   echo
   echo  "--${BOUNDARY}"
   echo  "Content-Type: TEXT/PLAIN; charset=US-ASCII; name="${TXTFILE}
   echo  "Content-Disposition: attachment; filename="`$(basename ${TXTFILE})
   echo
   cat ${TXTFILE}
   echo
   echo  "--${BOUNDARY}--"
} | sendmail -t

Just make sure you have sendmail in your bash path.

Alternative command to send attachment

(echo "Hi, this mail has an attachment."; uuencode attachment.txt attachment.txt) | mail -s "Some Subject" to-email@example.com 
Community
  • 1
  • 1
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • where i add the file? to $ZIP? is it var that hold the var? – shamir chaikin Mar 30 '11 at 11:25
  • Yes that example is attaching 2 files. 1: Shell var $ZIPFILE should point to a zip with the content-type `application/zip` and 2: $PDFFILE should point to a pdf with the content-type `application/pdf` So depending upon your needs please feel free to change the variable names and their content types. – anubhava Mar 30 '11 at 15:02
  • 1
    hi, at first i will acknowledge my gratitude to you. – shamir chaikin Mar 31 '11 at 14:01
  • .... second - my problem is that i recieve the txt file encoded without an option to decode it in my outlook. thanks – shamir chaikin Mar 31 '11 at 14:03
  • @user644535: I also use Outlook and able to receive all those attachments fine in Outlook. May I know what type of attachment you are trying to send eg: text, csv, doc, pdf etc then I can customize that code for your needs and update my answer. – anubhava Apr 02 '11 at 03:13
  • i will attachted my code and you may review your answer relate to what i did so far. FROM=new-pmm@xxxx.net TO=abc@xxxx.net SUBJECT="PMM DB CAPACITY" TXT= /tti/netrac/integration/scripts/maint_scripts/log.txt { echo "From: $FROM" echo "To: $TO" echo "Subject:" $SUBJECT echo "MIME-Version: 1.0" echo "--${BOUNDARY}" echo "Content-Type:TXT/PLAIN; charset=US-ASCII name=eeee" echo "Content-Disposition: attachment; filename=log" uuencode /tti/netrac/integration/scripts/maint_scripts/log.txt log.txt }|/usr/lib/sendmail -t – shamir chaikin Apr 03 '11 at 07:53
  • @user644535: I have provided the modified script in my answer above. Since you need to send only text attachment therefore there is no need to use uuencode here, I have tested it and I am able to open the attachment fine in my Outlook as well :) – anubhava Apr 04 '11 at 00:01
  • ... i done it but i didnt recieve any mail or error that correspond it, may be it relate to your comment - "Just make sure you have sendmail in your bash path. "? i gave the path as /usr/lib/sendmail -t. or rather i check some firewall definition? – shamir chaikin Apr 07 '11 at 07:59
  • @user644535: Yes please check whether you have an executable `sendmail in /usr/lib/sendmail` if not you can try alternative `uuencode/mail` command above in my answer. – anubhava Apr 07 '11 at 12:26