Generate & Send books to Kindle with Single Command
Idea
Because books can be sent to kindle by e-mail, linux shell scipts can do it well by a light mail system, such as neomutt with postfix. (Same idea should work in Mac and Windows with other packages At the end, we can send a book with a command easily. More, we can compile markdown notes to mobi file amd sent to kindle. Following are one of procedure.
Set Mail System
We use neomutt(or others) as a mail agent to organize mail, which generate mail and the command to send mail. Then postfix is used to sent mail to kindle mailbox, which excute command to send mail. Following is the introdution from their homepage:
NeoMutt is a command line mail reader (or MUA). It's a fork of Mutt with added features
What is Postfix? It is Wietse Venema's mail server that started life at IBM research as an alternative to the widely-used Sendmail program. Now at Google, Wietse continues to support postfix
Install neomutt and postfix:
1 | sudo pacman -S neomutt postfix |
from
option to a mail
adresse which has enrolled under your kindle account. Meanwhile, this
option can avoid our mail to be treated as junk: 1 | .neomuttrc |
I following the predure in ArchLinux wiki to set up postfix. We need
to uncommit the following line in /etc/postfix/aliases
, and
change you
to a real user name:
1 | root: you |
Once we have finished editing /etc/postfix/aliases
we
must run the postalias command and start/enable service:
1 | postfix /etc/postfix/aliases |
Test mail system and Send books to kindle
Now mail environment are done. We can test it:
1 | neomutt -s "Kindle mail env test" addressee |
If you receive this mail, you can send a pdf file as attachment to kindle:
1 | neomutt -s "Sent book to kindle" kindle_addresse -a book.pdf |
It maybe slow, you should wait or change other addressee. According
to neomutt guide, -s
means subject and -a
means attachments(can be multi).
Just for convenience, I write a shell script:
1 | send_to_kindle.sh |
And alias it to .bashrc
(or others):
1 | echo "alias kindle='/path/send_to_kindle.sh'" >> .bashrc |
Finally, books can be sent with single command:
1 | kindle book1 book1 |
Trouble Shooting
Some day I failed to send and get error:
1 | postdrop: warning: uid=1000: File too large |
1 | sudo postconf -e "message_size_limit=2048000000" |
Compile and Set Marddown notes to kindle
I always note in markdown when I take Cell Biology class, Genetics class etc. I want to review my note in kindle, so I write a scipt to do it. Markdown note compile to epub format by pandoc, then convert to mobi format by kindlegen.
KindleGen is a command line tool which enables publishers to work in an automated environment with a variety of source content including HTML, XHTML or EPUB. KindleGen converts this source content to a single file which supports both KF8 and Mobi formats enabling publishers to create great-looking books that work on all Kindle devices and apps.
Install pandoc and kindlegen(I find it in AUR)
1 | sudo pacman -S pandoc |
1 | makebook.sh |
Todo: Try to write an CSS file to create better format for pandoc.
References