Upload email-attachments automatically

So, the thing is, I want to have documents scanned by my printer on my nextcloud. My printer provides me two options to upload these scans. Either as a mail attachement or upload it to my dropbox, which isn’t an option for me as I can documents that have sensible information too.
So mail attachement it is…
I would create an seperate mail account just for this, is there a way nextcloud can scan this mail account and upload every single attachment sent to this mailaccount to a specified folder in my nextcloud?

Your help is very appreciated
with kind regards

It sounds theoretically possible if you run your own mail server and have the ability to programmatically export all extensions to a folder.
Wouldn’t it be much easier to scan to a local file, then just store that in a folder that is synced with Nextcloud? So the printer should not be responsible for the upload part of the task, you should leave that to the Nextcloud syncing client.

Sounds like the feature requested with

I’ve actually been able to do this directly from my printer. It’s an HP OfficeJet Pro and the HP Smart Android app allows me to scan and save it to the nextcloud app.

The scan to email is risky in that it’s a potential attack vector if someone finds that email and can upload a scripted attack file (image file with php in exif data, etc.). You can argue that your particular setup is protected against this, but you’re also allowing uploads that bypass the normal authentication/share restrictions layers.

Hi guys, I am pulling up this topic again because I have the same need (folder sync is no option because I also want to use the process from within a network that does not allow me “direct” acces to my NC environment).

Unfortunately I couldn’t get “Files from Mail” to run which is kind of too bad because it fits my need exactly.

Any help available?

Ok, since files_frommail seems to be the only solution to the problem, I am going to dive into it a bit deeper:

This refers to the information provided for the app on Github:


So I am doing ok regarding Mailparse (could add that directly as an extension to the PHP profile on my web station)

Step 2 is now the configuration of the mailserver

This is where I have my first problem: describe the directory where the file is supposed to be located should look like something like this, right?
files: “|/usr/bin/php -f /var/services/web/nextcloud/apps/files_frommail/lib/NextcloudMailCatcher.php”

I am not sure where to add the e-mail address now, from where mails are supposed to be forwarded to the php script.

Step 3 (assuming that I did Step 2 correctly), refreshing aliases.db

Bildschirmfoto 2021-03-10 um 12.05.05

When I process the command I receive an error: -ash: $: command not found

In the next stept Step (4) you have to edit the NextcloudMailCatcher.php with a few details

According to my understanding under ‘nextcloud’ you have to put in the URL of your NC installation, at ‘username’ put the e-mail address that shall be used, the password must be created using the NC credentials in the security section.

Is that understanding correct?

Now the test that you are supposed to do returns the same error: -ash: $: command not found

In the last Step (5) to my understanding you have to add the mailbox address to the NC

Where exactly/ how am I doing this?

I hope I have been able to describe my problems with the necessary level of detail in order for you to understand and - hopefully - provide feedback.


1 Like

tested GitHub - nextcloud/files_frommail: Recover your email attachments from your cloud with nextcloud 22 & php8, i works !!