< Back

# Scanning to your Nextcloud

Rationale

I’m trying to run my personal and my company life as paperless as possible. That’s why I’m using my scanner a lot, unfortunately I’m still often enough receiving paperwork which I’m then digitalizing. In this post I’d like to show you a tiny piece of software that’ll save me a lot of time while also improving my workflow by being able to more quickly scan paperwork and take care of handling the documents at a later point in time.

Problem

Scanning a document usually involves a couple of steps. Previously I either had to use my laptop or my smartphone to use a software to connect to the scanner, trigger scanning, optionally crop and save the file somewhere.

This would get especially cumbersome as the space close to my scanner isn’t especially well designed to put my laptop and besides this I’m constantly switching between using the scanner (open / close lid, swap documents, etc.) and use my laptop or smartphone to trigger the scans and use the Nextcloud app to save the files.

Prerequisites

To automate this process I’m relying on

Improvements

Now my scanner supports different ways of transmitted the scanned results, e.g. via mail or SMB (Samba, Windows Shares). Using SMB isn’t a viable way as it would require to have a device providing such a server when scanning. I’ve got a NAS but there are times where it’s switched off and I just don’t want to make my workflow rely on another piece of hardware.

What I did then, as an intermediate step, was to set up a dedicated mailbox for my scanner so it could send emails. Adding some commonly used email addresses to the built-in address book lead to just picking the right contact and sending mails with scan results there. Easy! That’s already a lot better.

Solution

Being this problem solving kind of person I desperately wanted to improve the whole deal, bringing me to what I’m dealing with every day: Software.

I didn’t want to make things too complex or overcomplicated, so my initial thought was to bring up a simple Node.js based service with an IMAP and WebDav client to fetch mails and upload attachments to my Nextcloud.

What happened was that I’ve been pretty much surprised by how bad the state of IMAP clients in TypeScript / JS was. I did a few dry runs but either the APIs were absolutely horrible, or they’ve been relying on ancient technologies and supporting newer TLS protocols.

Fortunately there was this one old piece of software on GitHub that provided all the basic functionality I needed.

I’ve just added one more option to configure allowed senders as I wanted to ensure only legit attachments will be forwarded to my Nextcloud.

Update: I’ve written the code for fetching mail from the IMAP inbox and putting then to WebDav from scratch in Python. While the old code was a good start it turned out to have difficulties with certain attachments. And as I’m not too familiar with Go, let alone the IMAP client used, I decided to go with something a lot simpler. So please go ahead and check it out here.

The authenticity of the sender will be ensured by my mail server via the typical means (SPF, DKIM, etc.) and once that layer is passed my services makes sure to only store the files when coming from specific senders. The scanner has their own email address which is not used for any other (external) other than sending mails to the Nextcloud.

Specimen on my scanner Scanned artifact in my Nextcloud
Photo of Scanner with Specimen Screenshot of scanned artifact

Finally

That said, my first test runs have been more than promising. I’m just putting my documents on the scanner now, hit the scan button and the documents are appearing in my Nextcloud in no time.

That being said, please feel free to check out imap2webdav and let me know if you use and like it.

Cheers, Marcus

Impressum • Mastodon