简体   繁体   中英

Using sendmail command while using uuencode to send attachment

I am trying to send an email in a shell script with the sendmail command. I have successfully sent the email with a .txt file attached. Here is an example of my working code:

       echo "Please enter a valid email address:"
       read EMAIL
       uuencode results.txt results.txt | sendmail $EMAIL

However, when I try to add a subject and body, for example:

       uuencode results.txt results.txt | sendmail $EMAIL<<EOF
       subject: Log file from today

       Test
       EOF

The message sends properly but with no attachments. Any ideas? I'm a C++ and VB guy.

Thanks.

Why not put the result of the uuencode into a variable? Assuming Bash:

ENCODED=`uuencode results.txt /dev/stdout`
echo "Please enter valid email address:"
read EMAIL
sendmail $EMAIL <<EOF
Subject: This is a test

Test file attached
--------------
$ENCODED
EOF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM