2013-07-31 13 views
8

Con i post precedenti in SO.com ho provato a creare il mio script per inviare e-mail al mio account Outlook con l'immagine incorporata nel corpo dell'e-mail. Ma i contenuti html vengono visualizzati in html piuttosto che visualizzare l'immagine. Per favore aiuto.Unix sendmail - immagine html incorporata non funzionante

Ecco il mio frammento di

{ 
echo "TO: [email protected]" 
echo "FROM: [email protected]>" 
echo "SUBJECT: Embed image test" 
echo "MIME-Version: 1.0" 
echo "Content-Type: multipart/related;boundary="--XYZ"" 

echo "--XYZ" 
echo "Content-Type: text/html; charset=ISO-8859-15" 
echo "Content-Transfer-Encoding: 7bit" 
echo "<html>" 
echo "<head>" 
echo "<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">" 
echo "</head>" 
echo "<body bgcolor="#ffffff" text="#000000">" 
echo "<img src="cid:part1.06090408.01060107" alt="">" 
echo "</body>" 
echo "</html>" 


echo "--XYZ" 
echo "Content-Type: image/jpeg;name="sathy.jpg"" 
echo "Content-Transfer-Encoding: base64" 
echo "Content-ID: <part1.06090408.01060107>" 
echo "Content-Disposition: inline; filename="sathy.jpg"" 
echo $(base64 sathy.jpg) 
echo "' />" 
echo "--XYZ--" 
}| /usr/lib/sendmail -t 

email che ho ricevuto contiene il sotto, piuttosto che visualizza l'immagine,

--XYZ 
Content-Type: text/html; charset=ISO-8859-15 
Content-Transfer-Encoding: 7bit 
<html> 
<head> 
<meta http-equiv=content-type content=text/html 
</head> 
<body bgcolor=#ffffff text=#000000> 
<img src=cid:part1.06090408.01060107 alt=> 
</body> 
</html> 
--XYZ 
Content-Type: image/jpeg;name=sathy.jpg 
Content-Transfer-Encoding: base64 
Content-ID: <part1.06090408.01060107> 
Content-Disposition: inline; filename=sathy.jpg 
/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAoAAD/4QNxaHR0cDov 
....base64 values..... 
/> 
--XYZ-- 
----XYZ-- 

Potete per favore aiutarmi in quello che mi manca

risposta

16

Il modo in cui si usa echo per stampare le intestazioni dei messaggi che mangia tutte le doppie virgolette - devi farle uscire con una barra retroversa (\") per farlo funzionare.

Inoltre, il tuo limite è sbagliato. Se si definisce boundary=--XYZ, ciascuna parte del messaggio deve iniziare con ----XYZ (è necessario aggiungere due trattini), altrimenti il ​​limite dovrebbe essere solo XYZ. E le intestazioni delle parti del mimo devono essere separate dai corpi da una linea vuota.

Se avete veramente bisogno di generare una mail da uno script di shell, quindi il mio consiglio sarebbe quello di sbarazzarsi di tutti l'eco e utilizzare un heredoc invece:

sendmail -t <<EOT 
TO: [email protected] 
FROM: <[email protected]> 
SUBJECT: Embed image test 
MIME-Version: 1.0 
Content-Type: multipart/related;boundary="XYZ" 

--XYZ 
Content-Type: text/html; charset=ISO-8859-15 
Content-Transfer-Encoding: 7bit 

<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"> 
</head> 
<body bgcolor="#ffffff" text="#000000"> 
<img src="cid:part1.06090408.01060107" alt=""> 
</body> 
</html> 

--XYZ 
Content-Type: image/jpeg;name="sathy.jpg" 
Content-Transfer-Encoding: base64 
Content-ID: <part1.06090408.01060107> 
Content-Disposition: inline; filename="sathy.jpg" 

$(base64 sathy.jpg) 
--XYZ-- 
EOT 
+0

1/0 grazie a voi. Quindi una spiegazione chiara e dettagliata. Sei forte!! – Sathy

+0

Risposta impressionante! Questo ha funzionato anche con me per 'mail', usando' mail -r "<[email protected]>" -s "Incorpora test immagine" -a "Versione MIME: 1.0" -a "Content-Type: multipart/related; boundary = \ "XYZ \" "[email protected] << EOT' e quindi avviare l'heredoc con' --XYZ' e tutto ciò che segue. – mat

+0

Come estendere questa funzione per utilizzare più immagini? – sugunan