Spedire un messaggio email con attachment da commandline: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 43: | Line 43: | ||
echo Hey, test this ! | biabam gallery2.sql.bz2 -s "Tryout Subject" gabriele.vivinetto@rvmgroup.it | echo Hey, test this ! | biabam gallery2.sql.bz2 -s "Tryout Subject" gabriele.vivinetto@rvmgroup.it | ||
== Utilizzare il binario sendmail per specificare un mittente == | |||
Con questo metodo è possibile anche '''specificare un mittente a piacere'''. | |||
Sendmail è fornito anche con postfix, verificarne la sua presenza: | |||
ls /usr/bin/sendmail | |||
Installare il pacchetto metamail, contenente l'eseguibile '''mimencode''' per gestire l'allegato | |||
apt-get install metamail | |||
Questo script invia l'email con in allegato un file di testo: | |||
<pre> | |||
filename="nomefile.txt" | |||
basefile="nomefile.txt" | |||
sender="Nome Cognome <nome.cognome@dominio.dom>" | |||
recipient="pippo@pluto.com,paperino@topolino.com" | |||
OGGETTO="Soggetto del messaggio" | |||
echo "From: $sender" > $TEMP_FILE | |||
# Specifica il mittente | |||
echo "To: $recipient" >> $TEMP_FILE | |||
# i destinatari | |||
echo "Subject: $OGGETTO" >> $TEMP_FILE | |||
# il soggetto | |||
echo "MIME-Version: 1.0" >> $TEMP_FILE | |||
# inia il messaggio MIME | |||
echo -e "Content-Type: multipart/mixed;\n\tBoundary=\"sendfile-attachment-boundary\"" >> $TEMP_FILE | |||
# Descrizione del tipo del messaggio: multicontenuto, separati dalla riga "sendfile-attachment-boundary" | |||
# notare che dopo il ";" bisogna nadare a capo e indentare la riga | |||
echo -e "\n" >> $TEMP_FILE | |||
# serve una riga vuota | |||
echo "--sendfile-attachment-boundary" >> $TEMP_FILE | |||
# inizio primo contenuto | |||
echo -e "Content-Type: text/plain;\n\tcharset=us-ascii" >> $TEMP_FILE | |||
# E' il testo del messaggio, quindi è un text/plain | |||
#anche qui notare l'a capo e il tab | |||
echo -e "\n" >> $TEMP_FILE | |||
# riga vuota | |||
echo -e "$MESSAGGIO" >> $TEMP_FILE | |||
# Inserire qui il messaggio | |||
echo -e "\n" >> $TEMP_FILE | |||
#riga vuota | |||
echo "--sendfile-attachment-boundary" >> $TEMP_FILE | |||
#separazione contenuto | |||
echo -e "Content-Type: text/plain;\n\tname=\"$basefile\"" >> $TEMP_FILE | |||
# Il primo allegato è un file testo | |||
# se fosse un file binario, usare: | |||
#echo -e "Content-Type: application/octet-stream;\n\tname=\"$basefile\"" >> $TEMP_FILE | |||
echo "Content-Transfer-Encoding: base64" >> $TEMP_FILE | |||
# specifica l'encoding | |||
echo -e "Content-Disposition: attachment;\n\tfilename=\"$basefile\"" >> $TEMP_FILE | |||
# deve essere un allegato | |||
echo -e "\n" >> $TEMP_FILE | |||
#riga vuota | |||
/usr/bin/mimencode $filename >> $TEMP_FILE | |||
# viene emesso su stdout la versione mimencodata dell'attachment | |||
echo "--sendfile-attachment-boundary--" >> $TEMP_FILE | |||
# separa il contenuto | |||
cat $TEMP_FILE | /usr/sbin/sendmail -t | |||
# viene inviato il file creato con sendmail, dicendogli con '''-t''' che i destinatari vanno letti dall'header | |||
</pre> | |||
Questo è un esempio di un file corretto da inviare: | |||
<pre> | |||
From: Gabriele Vivinetto <gabriele@rvmgroup.it> | |||
To: gabriele.vivinetto@rvmgroup.it,gabriele.mailing@rvmgroup.it | |||
Subject: Statistica Galimberti SANDI Settimana 19 | |||
MIME-Version: 1.0 | |||
Content-Type: multipart/mixed; | |||
Boundary="sendfile-attachment-boundary" | |||
--sendfile-attachment-boundary | |||
Content-Type: text/plain; | |||
charset=us-ascii | |||
In allegato Vi inviamo copia della statistica relativa la marchio SANDI per la settimana 19. | |||
A disposizione per qualsiasi chiarimento, | |||
Andrea Giupponi | |||
Galimberti S.p.A. | |||
--sendfile-attachment-boundary | |||
Content-Type: text/plain; | |||
name="galimb_SANDI200619.TXT" | |||
Content-Transfer-Encoding: base64 | |||
Content-Disposition: attachment; | |||
filename="galimb_SANDI200619.TXT" | |||
ICAgICAgICAgICAgIDszMTAwMjcyICAgICAgICAgICAgIDtTQU5ESVNLIENSVVpFUiBNSUNS | |||
TyA1MTJNQiAgICA7MDAwNDksOTA7ICAgIDE4MDUwNjswMDAwMDAzDQowNjE5NjU5MDEyMjc0 | |||
OzMxMDAwNDAgICAgICAgICAgICAgO1NBTkRJU0sgTVVMVElNRURJQSBDQVJEIDY0IE1CIDsw | |||
MDAyMiw5MDsgICAgMTgwNTA2OzAwMDAwMDENCjA2MTk2NTkwMTY5MTM7Q0YtMUdCICAgICAg | |||
.... | |||
RElBIENBUkQgNTEyIE1CIFJTICAgIDswMDA1NCw5MDsgICAgMTgwNTA2OzAwMDAwMTENCjYx | |||
OTY1OTAyMjE2NyA7MzEwMDA2NiAgICAgICAgICAgICA7U0FORElTSyBTRCBNSU5JIDUxMk1C | |||
ICAgICAgICAgOzAwMDQ0LDkwOyAgICAxODA1MDY7MDAwMDAwMw0KNjE5NjU5MDIyMTk4IDsz | |||
MTAwMDY1ICAgICAgICAgICAgIDtTQU5ESVNLIFNEIE1JTkkgMUdCICAgICAgICAgICA7MDAw | |||
NjksOTA7ICAgIDE4MDUwNjswMDAwMDAyDQo= | |||
--sendfile-attachment-boundary-- | |||
</pre> | |||
=== Riferimenti === | |||
*[http://groups.google.it/group/comp.mail.sendmail/browse_frm/thread/9d9ba09305c5cef1/9426de07641cca68 Google Gruppi: comp.mail.sendmail: Sendmail Attachments] | |||
*[http://www.freelists.org/archives/telnet/06-2002/msg00005.html Come specificare destinatari in BCC (non testato)] | |||
== Utilizzo di Mutt == | == Utilizzo di Mutt == | ||
Latest revision as of 17:43, 22 May 2006
Spedire un messaggio text only
echo "This is the message body" | mail -s "This is the Subject" recipient@company.com
Spedire un messaggio text only su più righe
mail -s "This is the Subject" recipient@company.com <<-END
This is the message body.
It can easily accommodate several lines.
and ${substitutions} work in the here-document.
END
Diagnostica
Per vedere cosa succede:
mail -v .....
Spedire un messaggio con un attachment
echo "Here is the report I promissed: " | uuencode -m -p Attachment.doc | mail -s "This message has an attachment" recipient@company.com
Oppure
(echo "Here is the report I promissed: " | uuencode -m Attachment.doc Attachment.doc ) | \ mail -s "This message has an attachment" recipient@company.com
Note Attachment.doc as two arguments to uuencode - once as the input file - once as the target filename.
Utilizzare biabam
Installare il pacchetto
apt-get install biabam
Per spedire l'attachment con un messaggio ed un soggetto:
echo Hey, test this ! | biabam gallery2.sql.bz2 -s "Tryout Subject" gabriele.vivinetto@rvmgroup.it
Utilizzare il binario sendmail per specificare un mittente
Con questo metodo è possibile anche specificare un mittente a piacere.
Sendmail è fornito anche con postfix, verificarne la sua presenza:
ls /usr/bin/sendmail
Installare il pacchetto metamail, contenente l'eseguibile mimencode per gestire l'allegato
apt-get install metamail
Questo script invia l'email con in allegato un file di testo:
filename="nomefile.txt" basefile="nomefile.txt" sender="Nome Cognome <nome.cognome@dominio.dom>" recipient="pippo@pluto.com,paperino@topolino.com" OGGETTO="Soggetto del messaggio" echo "From: $sender" > $TEMP_FILE # Specifica il mittente echo "To: $recipient" >> $TEMP_FILE # i destinatari echo "Subject: $OGGETTO" >> $TEMP_FILE # il soggetto echo "MIME-Version: 1.0" >> $TEMP_FILE # inia il messaggio MIME echo -e "Content-Type: multipart/mixed;\n\tBoundary=\"sendfile-attachment-boundary\"" >> $TEMP_FILE # Descrizione del tipo del messaggio: multicontenuto, separati dalla riga "sendfile-attachment-boundary" # notare che dopo il ";" bisogna nadare a capo e indentare la riga echo -e "\n" >> $TEMP_FILE # serve una riga vuota echo "--sendfile-attachment-boundary" >> $TEMP_FILE # inizio primo contenuto echo -e "Content-Type: text/plain;\n\tcharset=us-ascii" >> $TEMP_FILE # E' il testo del messaggio, quindi è un text/plain #anche qui notare l'a capo e il tab echo -e "\n" >> $TEMP_FILE # riga vuota echo -e "$MESSAGGIO" >> $TEMP_FILE # Inserire qui il messaggio echo -e "\n" >> $TEMP_FILE #riga vuota echo "--sendfile-attachment-boundary" >> $TEMP_FILE #separazione contenuto echo -e "Content-Type: text/plain;\n\tname=\"$basefile\"" >> $TEMP_FILE # Il primo allegato è un file testo # se fosse un file binario, usare: #echo -e "Content-Type: application/octet-stream;\n\tname=\"$basefile\"" >> $TEMP_FILE echo "Content-Transfer-Encoding: base64" >> $TEMP_FILE # specifica l'encoding echo -e "Content-Disposition: attachment;\n\tfilename=\"$basefile\"" >> $TEMP_FILE # deve essere un allegato echo -e "\n" >> $TEMP_FILE #riga vuota /usr/bin/mimencode $filename >> $TEMP_FILE # viene emesso su stdout la versione mimencodata dell'attachment echo "--sendfile-attachment-boundary--" >> $TEMP_FILE # separa il contenuto cat $TEMP_FILE | /usr/sbin/sendmail -t # viene inviato il file creato con sendmail, dicendogli con '''-t''' che i destinatari vanno letti dall'header
Questo è un esempio di un file corretto da inviare:
From: Gabriele Vivinetto <gabriele@rvmgroup.it>
To: gabriele.vivinetto@rvmgroup.it,gabriele.mailing@rvmgroup.it
Subject: Statistica Galimberti SANDI Settimana 19
MIME-Version: 1.0
Content-Type: multipart/mixed;
Boundary="sendfile-attachment-boundary"
--sendfile-attachment-boundary
Content-Type: text/plain;
charset=us-ascii
In allegato Vi inviamo copia della statistica relativa la marchio SANDI per la settimana 19.
A disposizione per qualsiasi chiarimento,
Andrea Giupponi
Galimberti S.p.A.
--sendfile-attachment-boundary
Content-Type: text/plain;
name="galimb_SANDI200619.TXT"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="galimb_SANDI200619.TXT"
ICAgICAgICAgICAgIDszMTAwMjcyICAgICAgICAgICAgIDtTQU5ESVNLIENSVVpFUiBNSUNS
TyA1MTJNQiAgICA7MDAwNDksOTA7ICAgIDE4MDUwNjswMDAwMDAzDQowNjE5NjU5MDEyMjc0
OzMxMDAwNDAgICAgICAgICAgICAgO1NBTkRJU0sgTVVMVElNRURJQSBDQVJEIDY0IE1CIDsw
MDAyMiw5MDsgICAgMTgwNTA2OzAwMDAwMDENCjA2MTk2NTkwMTY5MTM7Q0YtMUdCICAgICAg
....
RElBIENBUkQgNTEyIE1CIFJTICAgIDswMDA1NCw5MDsgICAgMTgwNTA2OzAwMDAwMTENCjYx
OTY1OTAyMjE2NyA7MzEwMDA2NiAgICAgICAgICAgICA7U0FORElTSyBTRCBNSU5JIDUxMk1C
ICAgICAgICAgOzAwMDQ0LDkwOyAgICAxODA1MDY7MDAwMDAwMw0KNjE5NjU5MDIyMTk4IDsz
MTAwMDY1ICAgICAgICAgICAgIDtTQU5ESVNLIFNEIE1JTkkgMUdCICAgICAgICAgICA7MDAw
NjksOTA7ICAgIDE4MDUwNjswMDAwMDAyDQo=
--sendfile-attachment-boundary--
Riferimenti
Utilizzo di Mutt
Vedi l'ottimo articolo Sending files as mail attachments
mutt -s "Birthday celebration" -a citymap.jpg all@friends.org \ < invitation.txt