2010-08-31 13:06:43 +00:00
<?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 >
< title > send mail from command line with attached file< / title >
< / head >
< body lang = "en" >
< script type = "text/javascript" > / / < ! [ C D A T A [
document.write('< div id = "blackpage" > < img src = "/Scratch/img/loading.gif" alt = "loading..." / > < / div > ');
// ]]>
< / script >
< div id = "content" >
2010-09-27 18:49:15 +00:00
< div id = "choix" >
< div class = "return" > < a href = "#entete" > ↓ Menu ↓ < / 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 >
< img src = "/Scratch/img/presentation.png" alt = "Presentation drawing" / >
2010-08-31 13:06:43 +00:00
< 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 isn’ t straightforward at all.
I didn’ t 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 didn’ t 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@> 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 > 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 didn’ t dare to use < code > telnet< / code > .
The command to use is:< / p >
< pre class = "twilight" >
sendmail -t -oi < span class = "Keyword" > < < / 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 < 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 >
2010-08-31 16:11:33 +00:00
< p > And to obtain the “ encoded” file in base64 I used:< / p >
< p > < code classs = "zsh" >
uuencode -m fic.jpg fic.jpg
< / code > < / p >
2010-08-31 13:06:43 +00:00
< p > That is all.
Sometimes technology is so easy to use.
2010-08-31 16:11:33 +00:00
If I need it another time I should consider to make a shell script to automatize this.< / p >
2010-08-31 13:06:43 +00:00
< / 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 >
Vous devez activer javascript pour commenter.
< / 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/" > Homepage< / a > < / li >
< li > < a href = "/Scratch/en/blog/" > Blog< / a > < / li >
2010-09-30 13:01:14 +00:00
< li > < a href = "/Scratch/en/softwares/" > Softwares< / a > < / li >
2010-09-28 01:00:51 +00:00
< li > < a href = "/Scratch/en/about/" > About< / a > < / li > < / ul >
2010-08-31 13:06:43 +00:00
< / div >
< div class = "flush" > < / div >
< hr / >
< div id = "next_before_articles" >
< div id = "previous_articles" >
previous entries
< div class = "previous_article" >
2010-09-28 15:10:12 +00:00
< a href = "/Scratch/en/blog/2010-08-23-Now-heberged-on-heroku/" > < span class = "nicer" > «< / span > Now hosted by heroku< / a >
2010-08-31 13:06:43 +00:00
< / div >
< div class = "previous_article" >
2010-09-28 15:10:12 +00:00
< a href = "/Scratch/en/blog/2010-07-09-Indecidabilities/" > < span class = "nicer" > «< / span > Undecidabilities (part 1)< / a >
2010-08-31 13:06:43 +00:00
< / div >
< div class = "previous_article" >
2010-09-28 15:10:12 +00:00
< a href = "/Scratch/en/blog/2010-07-31-New-style-after-holidays/" > < span class = "nicer" > «< / span > New style after holidays< / a >
2010-08-31 13:06:43 +00:00
< / div >
< / div >
< div id = "next_articles" >
next entries
2010-09-01 22:29:34 +00:00
< div class = "next_article" >
2010-09-28 15:10:12 +00:00
< a href = "/Scratch/en/blog/2010-09-02-base64-and-sha1-on-iPhone/" > base64 and sha1 on iPhone < span class = "nicer" > »< / span > < / a >
2010-09-01 22:29:34 +00:00
< / div >
2010-08-31 13:06:43 +00:00
2010-09-02 14:42:39 +00:00
< div class = "next_article" >
2010-09-28 15:10:12 +00:00
< a href = "/Scratch/en/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/" > Use git to calculate trusted mtimes < span class = "nicer" > »< / span > < / a >
2010-09-02 14:42:39 +00:00
< / div >
2010-08-31 13:06:43 +00:00
< / 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
2010-09-02 09:51:46 +00:00
Modified: 08/31/2010
2010-08-31 13:06:43 +00:00
< / 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 >