2011-03-22 16 views

Respuesta

0

No creo que sendmail te ayude con eso. Vaya por un cliente como mutt, y p. Ej. mutt -a file1 -a file2 -- [email protected]. O vaya por perl.

+0

No todos los sistemas tienen la capacidad de instalar mutt, por lo que su consejo no es muy útil para alguien que necesita utilizar Sendmail o mailx, como la cuestión preguntó :) – stevepastelan

+0

@stevepastelan Sendmail simplemente no puede hacer sin herramientas adicionales. Qué herramientas eliges depende de ti, por supuesto. – ShiDoiSi

+1

Pero, por supuesto, sendmail * puede * hacerlo. Solo se trata de cómo formatear los contenidos para pasarlos a sendmail. – stevepastelan

9

suponiendo que tiene uunecode disponible en su sistema, puede enviar un correo electrónico con varios archivos adjuntos de esta manera:

#!/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

El correo enviado desde el método sugerido anteriormente puede enviar el archivo adjunto, pero se recibe como un archivo codificado en el cliente de correo de Outlook. ¿Cómo enviar el archivo de manera que se reciba como un archivo decodificado como receptor? – greperror

0

Aquí es un script bash que utilizo para enviar informes de genero a la gente. Se envían como archivos adjuntos. Coloque su HTML en la variable "cuerpo" de la secuencia de comandos. Dejaré la parametrización de las variables a usted.

#!/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 
Cuestiones relacionadas