2021-04-18 10:23:24 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< title > YBlog - send mail from command line with attached file< / title >
< meta name = "keywords" content = "email, shell, web" / >
< link rel = "shortcut icon" type = "image/x-icon" href = "../../../../Scratch/img/favicon.ico" / >
2021-05-25 20:25:47 +00:00
< 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" / >
2021-04-18 10:23:24 +00:00
< 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 = "en" class = "article" >
< div id = "content" >
< div id = "header" >
< div id = "choix" >
< span id = "choixlang" >
< a href = "../../../../Scratch/fr/blog/2010-08-31-send-mail-from-command-line-with-attached-file/" > French< / a >
< / span >
< span class = "tomenu" > < a href = "#navigation" > ↓ Menu ↓< / a > < / span >
< span class = "flush" > < / span >
< / div >
< / div >
< div id = "titre" >
< h1 > send mail from command line with attached file< / h1 >
< / div >
< div class = "flush" > < / div >
< div id = "afterheader" class = "article" >
< 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 >
< 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 > 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 >
Not really readable.
After some research I found the solution.
Use MIME instead of `uuencode`.
Finally I made it manually using `sendmail`.
I didn" t dare to use `telnet`. The command to use is: ~~~~~~ {.zsh} sendmail -t -oi < mailcontent.txt ~ ~ ~ ~ ~ ~ Of course you need to create the ` mailcontent . txt ` file . It should contains: < 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 > And to obtain the “encoded” file in base64 I used:< / p >
< p > < code classs = "zsh" > uuencode -m fic.jpg fic.jpg ~~~~~~< / 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 = "afterarticle" >
< div id = "social" >
2021-05-25 20:25:47 +00:00
< a href = "/rss.xml" target = "_blank" rel = "noopener noreferrer nofollow" class = "social" > RSS< / a >
2021-04-18 10:23:24 +00:00
·
< a href = "https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/en/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/en/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/en/blog/Social-link-the-right-way/" > These social sharing links preserve your privacy< / a >
< / div >
< div id = "navigation" >
< a href = "../../../../" > Home< / a >
< span class = "sep" > ¦< / span >
< a href = "../../../../Scratch/en/blog" > Blog< / a >
< span class = "sep" > ¦< / span >
< a href = "../../../../Scratch/en/softwares" > Softwares< / a >
< span class = "sep" > ¦< / span >
< a href = "../../../../Scratch/en/about" > About< / 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" > & < / 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 >
< hr / >
< div style = "max-width: 100%" >
< a href = "https://cardanohub.org" >
< img src = "../../../../Scratch/img/ada-logo.png" class = "simple" style = "height: 16px ;
border-radius: 50%;
vertical-align:middle;
display:inline-block;" />
ADA:
< / a >
< code style = "display:inline-block;
word-wrap:break-word;
text-align: left;
vertical-align: top;
max-width: 85%;">
DdzFFzCqrhtAvdkmATx5Fm8NPJViDy85ZBw13p4XcNzVzvQg8e3vWLXq23JQWFxPEXK6Kvhaxxe7oJt4VMYHxpA2vtCFiP8fziohN6Yp
< / code >
< / div >
< / div >
< / div >
< / div >
< / div >
< / body >
< / html >