have been reading MIT Technology Review newsletter for some time already and it would be more convenient to read news on my Kindle device, but to do that I need manually load files to device and that is much work to do. Challenge was spotted, I have to automate this!
What is needed?
- Kindle device;
- Subscription to a newsletter (it can be any subscription, because script is creating HTML file from message body);
- Account in Google mail;
My first approach was to subscribe Kindle email directly to newsletter, but it failed because this mail is used to send documents in range of formats not plain email text and all mails were rejected, I learned that i have to send files. One of formats accepted by Kindle is *.html, that was good news because message bodies contain html tags I only need to pack all content in html file. Solution here was to use Google script to retrieve emails one by one, then create from message body html file and then send it to kindle. As easy it sound here as easy it was to accomplish that.
Script reads emails from designated folder converts message body to *.html file which is sent to Kindle email. Then message is deleted as well as file from Google drive. I have not seen any newsletter they all are handled now they are piling up in my Kindle device. Script has one function to which trigger has been set to run it in mornings from 6:00 to 7:00.
function send2Kindle() {
var label = GmailApp.getUserLabelByName(“MIT newsletter”);//Folder name in email mails are read.
var threads = label.getThreads();
var emailTo = “your_kindle_mail@kindle.com”, subject;
var msgStart1 = “<html><head><title>”, msgStart2 = “</title><head><body>”, msgEnd = “</body></html>”; //Had to add these tags for html file for Kindle to recognise that this is HTML file.
// Getting newsletter
for (var i = 0; i < threads.length; i++) {
var msg = threads[i].getMessages(), subject = msg[0].getSubject(), body = msg[0].getBody();
//Creating the file
var letterFile = DriveApp.createFile(subject + ’.html’, msgStart1 + subject + msgStart2 + body + msgEnd, MimeType.html);
//Sending mail
MailApp.sendEmail(emailTo, subject, ‘Have a goood read! Kind regards!’, {attachments: [letterFile]});
//Removing file
DriveApp.removeFile(letterFile);
//Removing message
GmailApp.moveThreadToTrash(threads[i]);
}
//END
}
In my mail account all newsletters from MIT Technology review are stored in separate folder and archived, I don’t even see them in my inbox. At the bottom I have picture illustrating that. Basically this folder is empty all the time because it is cleared in mornings.
This is device I am using, it may be old but I like the design of it. This Kindle does not have a touchscreen, sometimes it may be frustrating to write a WIFI name together with password using only 5 buttons.
Results: Google script successfully picks up newsletters and creates *.html file and then it is sent to Kindle email as a document attachment. Then Kindle is able to load file and lastly I am able to read news. Hope this was helpful to you, cheers!