↓ Archives ↓

Archive → December, 2015

Send email attachments to ownCloud

Three years have passed since my article about sending email attachments to Dropbox. A lot of stuff happened since then. For instance, since the end of safe harbor, we don’t trust U.S. based cloud providers as much as we (maybe) used to.

So, here’s an update on how to automatically save mail attachments (e.g. invoices and receipts) in a specific folder in ownCloud. The basic idea is to set up a billing@example.com email address and store all received PDF files in ownCloud.

So here, we go. We’re still using Uberspace for this because we still like it – even after three years. But again, you should be able to adapt this for any Linux based setup.

Configuring qmail and reformime

At Uberspace, you get an unlimited number of email addresses out of the box. Your primary is composed like this:

username@hostname.uberspace.de

Where username is your Uberspace username and hostname is the host your account is hosted on. What happens to emails coming this way is governed by a small file named ~/.qmail. In much the same way, you can use any email address that follows this format:

username-foo@hostname.uberspace.de

Where foo can be anything you like. To specify what should happen with emails coming in via this address, you can create a file called ~/.qmail-foo.

So, for instance, if you want all email PDF attachments sent to peter-owncloud@phoenix.uberspace.de to appear in ownCloud, create a ~/.qmail-owncloud file with the following content:

| /usr/bin/reformime -X /bin/sh -c "if [ "\${FILENAME#*.}" == "pdf" ]; then curl -X PUT -u username:password \"https://owncloud.example.com/remote.php/webdav/email-inbox/$(date +%Y%m%d%H%M%S)_\$FILENAME\" --data-binary @- ;fi"

Yep. That’s one single line. It uses reformime to extract all file attachments and then uploads those that end in .pdf to the email-inbox/ folder in your ownCloud.

Of course, it will be a good idea to create a separate user in your ownCloud which only has (create only) access to your email-inbox/ folder and use its credentials for the curl above.

Other than that, you’re all set. Now redirect your billing@example.com address to peter-owncloud@phoenix.uberspace.de and use that for services that send you invoices!