When using invoice processing software, you might find it useful to download emails and email attachments to a folder in a specific format so the invoice processing software can pick them up.
There are two paths to solving this today. One approach makes use of solutions that require you to have an email client installed (eg. Outlook) and requires a mail client license. Other approaches either lack direct email integration or require typically a multi-tenant cloud setup where your email information could be saved on cloud servers alongside other tenants requiring further security, privacy or other compliance assessments.
Mail Attachment Downloader PRO Server offers a sweet spot by offering flexible tooling for this purpose, letting you have full control of your email data while making it easy to customize it to your specific needs. As you read on, we’ll show how this product can do more than just saving attachments to a folder if your business needs it.
Let’s consider the case where you receive many invoices via email with (or without) attachments that then need to be saved for later consumption by invoice processing software.
Once the data is saved in a folder or a shared folder, you can either have the PRO Server save the invoice details into specific database fields OR run a custom script to hand it off to your line-of-business application OR have the invoice processing software monitor the folder and pick up the invoices and process them through the workflow. Also, the share could serve as a secondary backup for your invoices you’ve received.
You can also configure the program to save not only the invoices, but the email text or body as well very easily by just clicking on the ‘Save email text’ or ‘Save as .eml’ checkbox in the Rule filter screen (see below screenshots). This could come in handy if the invoice is in the body of the email itself (no attachment in the email, that is).
Also, let’s say that the Subject of that email is something like “Your Invoice #853290 is ready“. And we want to store this attachment under the folder of the Invoice # and use the filename that was sent prefixed by who it was From (from email address).
We will use the Mail Attachment Downloader PRO Server version prior to submitting the data to our invoice processing software that enables a LOT MORE flexibility in how you want the attachment named via a template mechanism as will be shown below.
Create a Rule Filter
First, since the PRO Server version lets you create many filters, let’s create one filter for Invoices.
Click on the Global Filters tab and the Add new filter button as shown below.
Enter the Rule filter name as something meaningful, we’ve called it ‘Invoices‘ as shown below.
Filter by SUBJECT
Second, since we want to only look at emails with a subject that contains the Invoice #, we need to add a filter to look for those emails. Click on the Add dropdown arrow -> Filters -> Header: Subject as shown below.
Since we know the format of the subject at-least has “Invoice #” we are going to first include that.
Extract the Invoice # from the SUBJECT
Third, since we want to extract the Invoice # for further invoice processing.
→ PRO Server also supports using the ExtractionWizard if you are not familiar with Regular Expressions. Makes it a lot easier to configure extractions this way.
Highly recommended that you go read this blog entry instead of the below: https://gearmage.com/blog/extract-data-emails-attachments/
With this post we will explore extracting data for invoices from the email using regular expressions. In a future post, we can walk you through how to use the Extraction Wizard if needed.
Since the Invoice # is in the Subject of the email, we will add a new extraction to the new rule we created as follows. Click on the Add dropdown -> Extractions -> Regex Extraction.
Rename the Extraction field to something meaningful like “{INVOICE_NUMBER}” as shown below and include a regular expression to extract text.
- In the Pattern field enter ^.*Invoice #(\d+)([a-z| ]*)$. If you notice symbols like ^, $ and \d and * are indicators to what to look for in the Subject. ^ implies start of the line and $ is the end of the line. The .* means include any number of characters followed by Invoice #. Since what follows Invoice # is a number we include (\d+). This becomes our first extraction field (which we will use as the Replace text). Following that could include any number of characters or spaces ([a-z]| ]*) followed by the end of the line $.
- In the Replace textbox, specify $1 which is the first match between the parentheses () we have specified in the Pattern, in this case (\d+).
Feel free to contact support if you have a different pattern to look for and we can help you craft this as needed. Refer to the Microsoft’s regular expression reference here for more.
Then you can Test the result out as shown above, if you notice TEST SUCCESS includes our extracted Invoice #. This will save with the invoice number for invoice processing into the field name.
NOTE: As mentioned before, if you are not well versed with regular expressions, we recommend using the Extraction Wizard instead.
And lastly, we will enter the save filename format as shown below:
{INVOICE_NUMBER}\{EMAIL_FROM}_{FILENAME}_{ID}{EXT}
The INVOICE_NUMBER field is the invoice number we extracted from the Subject. After which we include a \ to indicate this is a folder and then EMAIL_FROM which is the email address followed by the FILENAME, the ID of the email and EXT for the extension.
Lastly, click the Save button which will save the rule out and then you are ready to try downloading a few attachments to see if the extractions worked as intended.
If you were wondering what other information you could include in the Save filename format field, click on the little ? button which will open up a help option for this as shown below. As you can see, there are very many options to choose from giving complete flexibility to you.
If you find something that is missing in the features above, let us know.
Run download actions after save
You can then use any of the extracted fields along with any email specific fields (such as {FROM}, {TO} etc.) in the numerous download actions that are supported. This includes saving the data out to a database, saving to a .csv metadata file and many more.
Once the data is saved in these folders, you can trigger the invoice processing software via a script (if you have the PRO Server, you can run a script after saving the file to a folder) or folder monitoring as needed.
Once this is complete, if you have the PRO Server version you can now install the above as a Windows Service and not have to worry about having to log in to the box to process these attachments.
The Mail Attachment Downloader Free version also enables you to do some of the above but has the following limited features:
- For personal use only
- ID of the email in the filename. We highly recommend keeping the ID in the filename as if this is removed it may result in duplicate filenames that may result in overwriting of the filename.
- Fixed formatting of filename to include email headers are supported in a specific non-flexible format in the FREE version. The PRO versions include much more flexibility in how filenames are formatted as was shown above.
- From like ‘From (Bran E. <bran@gearmage.com>)’
- To like ‘To (Atul <atul@gearmage.com>)’
- Subject like ‘Subject (Our invoice)’
- Date like ‘Date(Wed, 24 Feb 2016 21_44_15 -0800)’
- The ability to create a folder based who the email is from.
- The ability to create a folder for every mailbox folder eg. “Inbox”.
While this is great, it does not allow us to be more prescriptive about how we want to store the attachments. So if you need more flexibility you should get the PRO or the PRO Server versions.
Further reading
Some interesting how-to links and posts for further exploration:
- Save emails to a database or even excel/csv from emails to a database
- Save to multiple folders from multiple accounts using multiple email rules.
- Send emails automatically after downloading files or attachments or body
- Unzip files, Decrypt pdf’s and run script’s
- Extract data and download emails for invoice processing
- How email rules work in-depth
Contact us
Contact us if you have any questions, suggestions about the functionality described in this article.