her.esy.fun/src/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/index.html
Yann Esposito (Yogsototh) 059fabd7d0
many minor details to update
2022-10-26 11:38:50 +02:00

123 lines
7.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>YBlog - Mail en ligne de commande avec un fichier join</title>
<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="../../../../css/y.css" />
<link rel="stylesheet" type="text/css" href="/css/legacy.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="../../../../Scratch/img/about/FlatAvatar@2x.png" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<!-- IndieAuth -->
<link href="https://twitter.com/yogsototh" rel="me">
<link href="https://github.com/yogsototh" rel="me">
<link href="mailto:yann.esposito@gmail.com" rel="me">
<link rel="pgpkey" href="../../../../pubkey.txt">
</head>
<body lang="fr" class="article">
<div id="content">
<div id="header">
<div id="choix">
<span id="choixlang">
<a href="../../../../Scratch/en/blog/2010-08-31-send-mail-from-command-line-with-attached-file/">Anglais</a>
</span>
<span class="tomenu"><a href="#navigation">↓ Menu ↓</a></span>
<span class="flush"></span>
</div>
</div>
<div id="titre">
<h1>Mail en ligne de commande avec un fichier join</h1>
</div>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<p>Jai 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 navais ni <code>pine</code> ni <code>mutt</code>. Seulement <code>mail</code> et <code>mailx</code>.</p>
<p>Ce quon trouve sur internet pour envoyer un mail avec fichier attaché cest ça&nbsp;:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode zsh"><code class="sourceCode zsh"><a class="sourceLine" id="cb1-1" title="1">uuencode fic.jpg fic.jpg <span class="kw">|</span> mail -s <span class="st">'Subject'</span></a></code></pre></div>
<p>Bon, alors, bête et discipliné jai essayé. Et bien, ça marche <em>presque</em> tout le temps. Pour mon fichier ça na pas marché du tout. Je lai 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 davoir un fichier attaché javais un message qui contenait quelque chose comme&nbsp;:</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>
Pas très lisible.
Après pas mal de recherche j" ai trouvé la solution. Le problème c'est `uuencode` 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. Donc finalement le mieux est de faire ça "à la main" avec `sendmail`. Je n'ai quand même pas utilisé `telnet`. La commande à lancer est : ~~~~~~ {.zsh} sendmail -t -oi < mailcontent.txt ~~~~~~ Bien entendu il faut créer le fichier `mailcontent.txt` qui contient : <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&nbsp;:</p>
<p><code classs="zsh"> uuencode -m fic.jpg fic.jpg ~~~~~~</p>
<p>Et voilà. Parfois la technique cest tellement simple. Si jen ai besoin encore quelques fois, je pense que jécrirai un émetteur de mail en shell.</p>
</div>
<div id="afterarticle">
<div id="social">
<a href="/rss.xml" target="_blank" rel="noopener noreferrer nofollow" class="social">RSS</a>
·
<a href="https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/%20via%20@yogsototh" target="_blank" rel="noopener noreferrer nofollow" class="social">Tweet</a>
·
<a href="http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/" target="_blank" rel="noopener noreferrer nofollow" class="social">FB</a>
<br />
<a class="message" href="../../../../Scratch/fr/blog/Social-link-the-right-way/">Ces liens sociaux préservent votre vie privée</a>
</div>
<div id="navigation">
<a href="../../../../">Accueil</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/softwares">Logiciels</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/about">Auteur</a>
</div>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div id="bottom">
<div>
Published on 2010-08-31
</div>
<div>
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
</div>
<div>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Yann Esposito©</a>
</div>
<div>
Done with
<a href="http://www.vim.org" target="_blank" rel="noopener noreferrer nofollow"><strike>Vim</strike></a>
<a href="http://spacemacs.org" target="_blank" rel="noopener noreferrer nofollow">spacemacs</a>
<span class="pala">&amp;</span>
<a href="http://nanoc.ws" target="_blank" rel="noopener noreferrer nofollow"><strike>nanoc</strike></a>
<a href="http://jaspervdj.be/hakyll" target="_blank" rel="noopener noreferrer nofollow">Hakyll</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>