2011-03-22 12 views

Odpowiedz

0

Nie sądzę, że sendmail pomoże ci z tym. Przejdź do klienta takiego jak mutt i wykonaj np. mutt -a file1 -a file2 -- [email protected]. Lub przejdź na perl.

+0

nie wszystkie systemy będą mieli możliwość instalowania kundla, więc rada nie jest bardzo pomocne dla kogoś, kto potrzebuje używać sendmail lub mailx, jak zadał pytanie :) – stevepastelan

+0

@stevepastelan Sendmail po prostu nie może zrobić bez dodatkowych narzędzi. To, które narzędzia wybierzesz, zależy oczywiście od Ciebie. – ShiDoiSi

+1

Ale oczywiście sendmail * może * to zrobić. To tylko kwestia sposobu formatowania zawartości do przekazania do sendmaila. – stevepastelan

9

Zakładając masz uunecode dostępny w systemie można wysłać e-mail z wieloma załącznikami tak:

#!/bin/bash 

... 
... 
... 
BOUNDARY="=== This is the boundary between parts of the message. ===" 

{ 
    echo "From: $MAILFROM" 
    echo "To: $MAILTO" 
    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 somewhat readable with old " 
    echo "  mail software." 
    echo 
    echo "--${BOUNDARY}" 
    echo "Content-Type: TEXT/PLAIN; charset=US-ASCII" 
    echo 
    echo "This email comes with multiple attachments." 
    echo 
    echo 
    echo "--${BOUNDARY}" 
    echo "Content-Type: application/zip; charset=US-ASCII; name="${ZIPFILE} 
    echo "Content-Disposition: attachment; filename="`basename ${ZIPFILE}` 
    echo 
    uuencode $ZIPFILE $ZIPFILE 
    echo 
    echo "--${BOUNDARY}--" 
    echo "Content-Type: application/pdf; charset=US-ASCII; name="${PDFFILE} 
    echo "Content-Disposition: attachment; filename="`basename ${PDFFILE}` 
    echo 
    uuencode $PDFFILE $PDFFILE 
    echo 
    echo "--${BOUNDARY}--" 
} | /usr/lib/sendmail -t 
+0

Poczta wysłana z sugerowanej powyżej metody jest w stanie wysłać plik w załączniku, ale jest odbierany jako zakodowany plik w kliencie poczty programu Outlook. Jak wysłać plik tak, aby został odebrany jako zdekodowany plik jako koniec odbiorcy? – greperror

0

Oto skrypt bash używać do wysyłania raportów wygenerować z ludźmi. Są wysyłane jako załączniki. Umieść swój kod HTML w zmiennej "body" skryptu. Pozostawię parametryzację zmiennych do ciebie.

#!/bin/bash 

function get_mimetype(){ 
file --mime-type "$1" | sed 's/.*: //' 
} 

from="[email protected]" 
to="[email protected]" 
subject="Your Report my Lord" 
boundary="=== Boundary ===" 
body="The reports are attached to this email" 
declare -a attachments 
attachments=("fileOne.out" "fileTwo.out" "fileThree.out" "file-et-cetera.out") 

# Build headers 
{ 

printf '%s\n' "From: $from 
To: $to 
Subject: $subject 
Mime-Version: 1.0 
Content-Type: multipart/mixed; boundary=\"$boundary\" 

--${boundary} 
Content-Type: text/plain; charset=\"US-ASCII\" 
Content-Transfer-Encoding: 7bit 
Content-Disposition: inline 

$body 
" 

for file in "${attachments[@]}"; do 

     [ ! -f "$file" ] && echo "Attachment $file not found, omitting file" >&2 && continue 

     mimetype=$(get_mimetype "$file") 

    printf '%s\n' "--${boundary} 
Content-Type: $mimetype 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=\"$file\" 
    " 

    base64 "$file" 
    echo 
done 

# print last boundary with closing -- 
printf '%s\n' "--${boundary}--" 

} | sendmail -t -oi 
Powiązane problemy