Send attached file with mailx
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?
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
精彩评论