scratch/output/Scratch/en/blog/2010-08-31-send-mail-from-command-line-with-attached-file/index.html
Yann Esposito (Yogsototh) c53114f72a Merge branch 'master' into next
(Recompiled)

Conflicts:
	output/Scratch/assets/css/main.css
	output/Scratch/en/blog/Yesod-excellent-ideas/index.html
	output/Scratch/en/blog/feed/feed.xml
	output/Scratch/en/blog/index.html
	output/Scratch/en/index.html
	output/Scratch/fr/blog/Yesod-excellent-ideas/index.html
	output/Scratch/fr/blog/feed/feed.xml
	output/Scratch/fr/blog/index.html
	output/Scratch/fr/index.html
	output/Scratch/sitemap.xml
	output/index.html
2011-11-16 13:08:26 +01:00

247 lines
No EOL
10 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.

<?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/yannespositocomen"/>
<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>send mail from command line with attached file</title>
</head>
<body lang="en" class="article">
<script type="text/javascript">// <![CDATA[
document.write('<div id="blackpage"><img src="/Scratch/img/loading.gif" alt="loading..."/></div>');
// ]]>
</script>
<div id="content">
<div id="choix">
<div class="return"><a href="#entete">&darr; Menu &darr;</a></div>
<div id="choixlang">
<a href="/Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/" onclick="setLanguage('fr')">en Français</a>
</div>
<div class="flush"></div>
</div>
<div id="titre">
<h1>
send mail from command line with attached file
</h1>
</div>
<div class="flush"></div>
<div class="flush"></div>
<div id="afterheader">
<div class="corps">
<p>I had to send a mail using only command line.
I was surprised it isnt straightforward at all.
I didnt had <code>pine</code> nor <code>mutt</code> or anything like that.
Just <code>mail</code> and <code>mailx</code>.</p>
<p>What Internet say (via google) is</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>I tried it.
And it works almost each times.
But for my file, it didnt worked.
I compressed it to <code>.gz</code>, <code>.bz2</code> and <code>.zip</code>.
Using <code>.bz2</code> format it worked nicely, but not with other formats.
Instead of having an attached file I saw this in my email.</p>
<pre>
begin 664 fic.jpg
M(R$O=7-R+V)I;B]E;G8@&gt;G-H"GAL&lt;STD,0H*9F]R(&QI;F4@:6X@)"@\("1X
M;',@*0H@("`@9&amp;-R/20H96-H;R`D;&amp;EN92!\(&amp;%W:R`M1EP[("=[&lt;')I;G0@
...
M93U&lt;(FUO='-&lt;(CX\=F%L=64^/&amp;ET96T@;F%M93U&lt;(F-T&gt;%]M8UPB/BD\=F%L
M=64O/B@\+VET96T^*2-&lt;)#$\=F%L=64^)&amp;ME&gt;7=O&lt;F1S/"]V86QU93Y&lt;)#(C
end
</pre>
<p>Not really readable.
After some research I found the solution.
Use MIME instead of <code>uuencode</code>.</p>
<p>Finally I made it manually using <code>sendmail</code>.
I didnt dare to use <code>telnet</code>.
The command to use is:</p>
<pre class="twilight">
sendmail -t -oi <span class="Keyword">&lt;</span> mailcontent.txt
</pre>
<p>Of course you need to create the <code>mailcontent.txt</code> file.
It should contains:</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 &lt;http://www.etresoft.com&gt;.
---
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>And to obtain the “encoded” file in base64 I used:</p>
<p><code classs="zsh">
uuencode -m fic.jpg fic.jpg
</code></p>
<p>That is all.
Sometimes technology is so easy to use.
If I need it another time I should consider to make a shell script to automatize this.</p>
</div>
<div id="choixrss">
<a id="rss" href="http://feeds.feedburner.com/yannespositocomen">
Subscribe
</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">Comments</div>');
</script>
<div class="flush"></div>
<div class="corps" id="comment">
<h2 class="first">comments</h2>
<noscript>
You must enable javascript to comment.
</noscript>
<script type="text/javascript">
var idcomments_acct = 'a307f0044511ff1b5cfca573fc0a52e7';
var idcomments_post_id = '/Scratch/en/blog/2010-08-31-send-mail-from-command-line-with-attached-file/';
var idcomments_post_url = 'http://yannesposito.com/Scratch/en/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/en/">Home</a></li>
<li><a href="/Scratch/en/blog/">Blog</a></li>
<li><a href="/Scratch/en/softwares/">Softwares</a></li>
<li><a href="/Scratch/en/about/">About</a></li></ul>
</div>
<div class="flush"></div>
<hr/>
<div id="next_before_articles">
<div id="previous_articles">
previous entries
<div class="previous_article">
<a href="/Scratch/en/blog/2010-08-23-Now-heberged-on-heroku/"><span class="nicer">«</span>&nbsp;Now hosted by heroku</a>
</div>
<div class="previous_article">
<a href="/Scratch/en/blog/2010-07-09-Indecidabilities/"><span class="nicer">«</span>&nbsp;Undecidabilities (part 1)</a>
</div>
<div class="previous_article">
<a href="/Scratch/en/blog/2010-07-31-New-style-after-holidays/"><span class="nicer">«</span>&nbsp;New style after holidays</a>
</div>
</div>
<div id="next_articles">
next entries
<div class="next_article">
<a href="/Scratch/en/blog/2010-09-02-base64-and-sha1-on-iPhone/">base64 and sha1 on iPhone&nbsp;<span class="nicer">»</span></a>
</div>
<div class="next_article">
<a href="/Scratch/en/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/">Use git to calculate trusted mtimes&nbsp;<span class="nicer">»</span></a>
</div>
<div class="next_article">
<a href="/Scratch/en/blog/2010-10-06-New-Blog-Design-Constraints/">New Blog Design Constraints&nbsp;<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/">Copyright ©, Yann Esposito</a>
</div>
<div id="lastmod">
Created: 08/31/2010
Modified: 08/31/2010
</div>
<div>
Entirely done with
<a href="http://www.vim.org">Vim</a>
and
<a href="http://nanoc.stoneship.org">nanoc</a>
</div>
<div>
<a href="/Scratch/en/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/en/blog/feed/feed.xml">[rss]</a>
</div>
</div>
<div class="clear"></div>
</div>
</body>
</html>