247 lines
No EOL
11 KiB
HTML
247 lines
No EOL
11 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
|
|
|
|
<meta name="keywords" content="email, shell, web">
|
|
|
|
<link rel="shortcut icon" type="image/x-icon" href="/Scratch/img/favicon.ico" />
|
|
<link rel="stylesheet" type="text/css" href="/Scratch/assets/css/main.css" />
|
|
<link rel="stylesheet" type="text/css" href="/Scratch/css/twilight.css" />
|
|
<link rel="stylesheet" type="text/css" href="/Scratch/css/idc.css" />
|
|
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/yannespositocomfr"/>
|
|
|
|
<link rel="alternate" lang="fr" xml:lang="fr" title="Envoyer un mail en ligne de commande avec un fichier attaché" type="text/html" hreflang="fr" href="/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/" />
|
|
<link rel="alternate" lang="en" xml:lang="en" title="send mail from command line with attached file" type="text/html" hreflang="en" href="/Scratch/en/blog/2010-08-31-send-mail-from-command-line-with-attached-file/" />
|
|
<script type="text/javascript" src="/Scratch/js/jquery-1.3.1.min.js"></script>
|
|
<script type="text/javascript" src="/Scratch/js/jquery.cookie.js"></script>
|
|
<script type="text/javascript" src="/Scratch/js/index.js"></script>
|
|
<!--[if lt IE 9]>
|
|
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
|
|
<![endif]-->
|
|
<title>Envoyer un mail en ligne de commande avec un fichier attaché</title>
|
|
</head>
|
|
<body lang="fr" class="article">
|
|
<script type="text/javascript">// <![CDATA[
|
|
document.write('<div id="blackpage"><img src="/Scratch/img/loading.gif" alt="Chargement en cours..."/></div>');
|
|
// ]]>
|
|
</script>
|
|
|
|
<div id="content">
|
|
|
|
<div id="choix">
|
|
<div class="return"><a href="#entete">↓ Menu ↓</a></div>
|
|
<div id="choixlang">
|
|
<a href="/Scratch/en/blog/2010-08-31-send-mail-from-command-line-with-attached-file/" onclick="setLanguage('en')">in English</a>
|
|
</div>
|
|
<div class="flush"></div>
|
|
</div>
|
|
<div id="titre">
|
|
<h1>
|
|
Envoyer un mail en ligne de commande avec un fichier attaché
|
|
</h1>
|
|
|
|
</div>
|
|
<div class="flush"></div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flush"></div>
|
|
<div id="afterheader">
|
|
<div class="corps">
|
|
<p>J’ai dû envoyer un mail en ligne de commande récemment.
|
|
Quelle ne fût pas ma surprise lorsque je constatais que ce n’était vraiment pas évident.
|
|
Je n’avais ni <code>pine</code> ni <code>mutt</code>. Seulement <code>mail</code> et <code>mailx</code>.</p>
|
|
|
|
<p>Ce qu’on trouve sur internet pour envoyer un mail avec fichier attaché c’est ça :</p>
|
|
|
|
<pre class="twilight">
|
|
uuencode fic.jpg fic.jpg <span class="Keyword">|</span> mail -s <span class="String"><span class="String">'</span>Subject<span class="String">'</span></span>
|
|
</pre>
|
|
|
|
<p>Bon, alors, bête et discipliné j’ai essayé.
|
|
Et bien, ça marche <em>presque</em> tout le temps.
|
|
Pour mon fichier ça n’a pas marché du tout.
|
|
Je l’ai compressé au format <code>.gz</code>, <code>.bz2</code> et <code>.zip</code>.
|
|
Avec le format <code>.bz2</code> le mail reçu avait bien un fichier attaché.
|
|
Mais avec les formats <code>.gz</code> et <code>.zip</code>, ça ne fonctionnait pas.
|
|
Au lieu d’avoir un fichier attaché j’avais un message qui contenait quelque chose comme :</p>
|
|
|
|
<pre>
|
|
begin 664 fic.jpg
|
|
M(R$O=7-R+V)I;B]E;G8@>G-H"GAL<STD,0H*9F]R(&QI;F4@:6X@)"@\("1X
|
|
M;',@*0H@("`@9&-R/20H96-H;R`D;&EN92!\(&%W:R`M1EP[("=[<')I;G0@
|
|
...
|
|
M93U<(FUO='-<(CX\=F%L=64^/&ET96T@;F%M93U<(F-T>%]M8UPB/BD\=F%L
|
|
M=64O/B@\+VET96T^*2-<)#$\=F%L=64^)&ME>7=O<F1S/"]V86QU93Y<)#(C
|
|
end
|
|
</pre>
|
|
|
|
<p>Pas très lisible.
|
|
Après pas mal de recherche j’ai trouvé la solution.
|
|
Le problème c’est <code>uuencode</code> qui est une méthode qui devrait devenir obsolète pour envoyer les fichiers.
|
|
Il vaut mieux utiliser le format MIME pour envoyer des fichiers attachés.</p>
|
|
|
|
<p>Donc finalement le mieux est de faire ça “à la main” avec <code>sendmail</code>.
|
|
Je n’ai quand même pas utilisé <code>telnet</code>.
|
|
La commande à lancer est :</p>
|
|
|
|
<pre class="twilight">
|
|
sendmail -t -oi <span class="Keyword"><</span> mailcontent.txt
|
|
</pre>
|
|
|
|
<p>Bien entendu il faut créer le fichier <code>mailcontent.txt</code> qui contient :</p>
|
|
|
|
<pre>
|
|
From: from@mail.com
|
|
To: to@mail.com
|
|
Subject: View the attached file
|
|
Mime-Version: 1.0
|
|
Content-Type: multipart/mixed; boundary="-"
|
|
|
|
This is a MIME encoded message. Decode it with "Decoder"
|
|
or any other MIME reading software. Decoder is available
|
|
at <http://www.etresoft.com>.
|
|
---
|
|
Content-Type: image/jpeg; name="fic.jpg"
|
|
Content-Transfer-Encoding: base64
|
|
Content-Disposition: inline; filename="fic.jpg"
|
|
|
|
H4sICB6Ke0wAA2Rjcl93aXRob3V0X2tleXdvcmQuY3N2ANSdW5ubOJPH7/e7
|
|
7Brw+dmrTk8yk7yTSTaZeWd2b/TIIGy6MRAE7ng+/VaJgwF3g522SsxN2+3T
|
|
/4eOJamqmARP+yibvI8ykUYim+x5EE2euBfIyd3byZ+fvvzr7svbu8ndTx/f
|
|
...
|
|
</pre>
|
|
|
|
<p>Et pour avoir le code il suffit de lancer la commande :</p>
|
|
|
|
<p><code classs="zsh">
|
|
uuencode -m fic.jpg fic.jpg
|
|
</code></p>
|
|
|
|
<p>Et voilà.
|
|
Parfois la technique c’est tellement simple.
|
|
Si j’en ai besoin encore quelques fois, je pense que j’écrirai un émetteur de mail en shell.</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="choixrss">
|
|
<a id="rss" href="http://feeds.feedburner.com/yannespositocomfr">
|
|
s'abonner
|
|
</a>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(){
|
|
$('#comment').hide();
|
|
$('#clickcomment').click(showComments);
|
|
});
|
|
function showComments() {
|
|
$('#comment').show();
|
|
$('#clickcomment').fadeOut();
|
|
}
|
|
document.write('<div id="clickcomment">Commentaires</div>');
|
|
</script>
|
|
<div class="flush"></div>
|
|
<div class="corps" id="comment">
|
|
<h2 class="first">commentaires</h2>
|
|
<noscript>
|
|
Vous devez activer javascript pour commenter.
|
|
</noscript>
|
|
|
|
<script type="text/javascript">
|
|
var idcomments_acct = 'a307f0044511ff1b5cfca573fc0a52e7';
|
|
var idcomments_post_id = '/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/';
|
|
var idcomments_post_url = 'http://yannesposito.com/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/';
|
|
</script>
|
|
<span id="IDCommentsPostTitle" style="display:none"></span>
|
|
<script type='text/javascript' src='/Scratch/js/genericCommentWrapperV2.js'></script>
|
|
|
|
</div>
|
|
|
|
<div id="entete" class="corps_spaced">
|
|
<div id="liens">
|
|
<ul><li><a href="/Scratch/fr/">Bienvenue</a></li>
|
|
<li><a href="/Scratch/fr/blog/">Blog</a></li>
|
|
<li><a href="/Scratch/fr/softwares/">Softwares</a></li>
|
|
<li><a href="/Scratch/fr/about/">À propos</a></li></ul>
|
|
</div>
|
|
<div class="flush"></div>
|
|
<hr/>
|
|
<div id="next_before_articles">
|
|
<div id="previous_articles">
|
|
articles précédents
|
|
|
|
<div class="previous_article">
|
|
<a href="/Scratch/fr/blog/2010-08-23-Now-heberged-on-heroku/"><span class="nicer">«</span> Maintenant sur Heroku</a>
|
|
</div>
|
|
|
|
|
|
<div class="previous_article">
|
|
<a href="/Scratch/fr/blog/2010-07-09-Indecidabilities/"><span class="nicer">«</span> Indécidabilités (partie 1)</a>
|
|
</div>
|
|
|
|
|
|
<div class="previous_article">
|
|
<a href="/Scratch/fr/blog/2010-07-31-New-style-after-holidays/"><span class="nicer">«</span> Nouveau style après les vacances</a>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
<div id="next_articles">
|
|
articles suivants
|
|
|
|
<div class="next_article">
|
|
<a href="/Scratch/fr/blog/2010-09-02-base64-and-sha1-on-iPhone/">base64 et sha1 sur iPhone <span class="nicer">»</span></a>
|
|
</div>
|
|
|
|
|
|
<div class="next_article">
|
|
<a href="/Scratch/fr/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/">Utilisation de git pour calculer les mtimes <span class="nicer">»</span></a>
|
|
</div>
|
|
|
|
|
|
<div class="next_article">
|
|
<a href="/Scratch/fr/blog/2010-10-06-New-Blog-Design-Constraints/">Contraintes du design de ce blog <span class="nicer">»</span></a>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
<div class="flush"></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div id="bottom">
|
|
<div>
|
|
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.fr">Droits de reproduction ©, Yann Esposito</a>
|
|
</div>
|
|
<div id="lastmod">
|
|
Écrit le : 31/08/2010
|
|
modifié le : 31/08/2010
|
|
</div>
|
|
<div>
|
|
Site entièrement réalisé avec
|
|
<a href="http://www.vim.org">Vim</a>
|
|
et
|
|
<a href="http://nanoc.stoneship.org">nanoc</a>
|
|
</div>
|
|
<div>
|
|
<a href="/Scratch/fr/validation/">Validation</a>
|
|
<a href="http://validator.w3.org/check?uri=referer"> [xhtml] </a>
|
|
.
|
|
<a href="http://jigsaw.w3.org/css-validator/check/referer?profile=css3"> [css] </a>
|
|
.
|
|
<a href="http://validator.w3.org/feed/check.cgi?url=http%3A//yannesposito.com/Scratch/fr/blog/feed/feed.xml">[rss]</a>
|
|
</div>
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>
|
|
</body>
|
|
</html> |