If you've spent any time configuring user authentication on... Full Story
By Manny Fernandez
May 12, 2020
Workflow: Auto Saving Mail Attachments from Specific People
I have a colleague that sends out an inventory report daily at 1:00AM. I want to save this information because it is useful to me. The question is how would I do this to process it in a way that makes sense. Obviously, I do not want to save every day for every year. Here is my workflow for this article.
- Monitor inbox for emails meeting particular criteria (from, subject contains, etc)
- I want to move the attachment to a particular folder with Automator.
- Have Hazel monitor the folder.
- Delete
.pngand.jpgwhich came in asattachments - Rename the old file in the folder that has been there longer than 1 day
- Rename new file with
XXFT_in the name and was createdtoday toinventory.pdf - Delete old messages so I do not keep downloading them into the folder.
- Delete
- This will allow my link in
Shortcut Barpoint to the latest inventory report.
Here is how I did it.
Mail Rules
First thing I needed to was create some Mail rules that will move some messages around and delete old messages.

In this mail rule, I am monitoring all emails that are recv’d FROM a particular email address @fortinet.com with a subject line, that contain a repeated pattern all emails containing inventory have in the subject line. It then moves them to a Inv folder (mailbox in Apple speak) underneath my main account.

This rule is very similar to the previous one, however if the date received is less than and in my case I chose 1 day since I receive these emails daily. In this case, any emails that match that criteria, will be deleted automatically.
Automator
Apple’s macOS X comes with an application named Automator . You may have seen me use this in the past on other articles. I find it very useful.

Here we see the Automator screen. I will break down what I did.
- Under the leftmost portion of the screen, you will see
Libraryand under that, you will chooseMail - Next you will select the
Get Specified Mail items which will allow us to tellAutomatorwhat folder or “Mailbox” we want it to monitor. - Next we will drag the
Get Attachments from Mail Messagesto the right. - Now we click
Addand add the folder or mailbox that you want it to look at. - Finally, you set the
Save attachment in:location. I created a folder calledInventory Staging.
Hazel
The next section is the monitoring and taking action portion of the files in a folder. For this, I use Hazel. It is truly an amazing piece of code that I use for all sorts of things.

In Hazel, I have Inventory Staging folder defined under the Folders section of Hazel. On the right side, you will see the different rules for that folder.

The first rule, is to clean up any pictures that were received in the email as attachments, such as .png files and .jpg files (usually from the email signatures), and it is going to move those to the trash.

Next, we are going to get any file with a .pdf that was NOT created today (The time it runs), it will rename it to old- and the name of the file. This is really to save one version of the file.

Lastly, I will get any file that contains XXFT_ which is the way all the files start, that ALSO were created Today, I am going to rename them to INVENTORY.PDF
Schedule Cron Job
Now the finishing touch is to schedule the cron job and add the shortcut to the Shortcut Bar and we are done.
mannyfernandez:~$crontab -l 00 2 * * 1-5 /Users/mannyfernandez/Data/Backups/Scripts/GetAttachments.app mannyfernandez:~$
To automate this on macOS and Linux, you can use the crontab -e command. I like to add the text below with # before each line so you can see it in the cron tab.
* * * * * command to execute
│ │ │ │ │
│ │ │ │ └─── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
│ │ │ └──────── month (1 - 12)
│ │ └───────────── day of month (1 - 31)
│ └────────────────── hour (0 - 23)
└─────────────────────── min (0 - 59)Looking at my example
In my example, I want to run the script every weekday at 2:00AM. As you can see in the sample text:
- We are using the first place holder which represents
minto say that at00 minutes - The next section represents
hoursso I am saying at2 hours. When combined, it represents2:00AM - We do not care about the day of month, so we keep the next spot at the default
* - Same with month, so that too will stay at
*. - Next we want Monday-Friday, which is represented in numeric value, where
0representsSundayand6representsSaturday - And finally the path and script name.
To check the cron jobs that are scheduled, you can use crontab -l
mannyfernandez:~$crontab -l 00 2 * * 1-5 /Users/mannyfernandez/Data/Backups/Scripts/GetAttachments.app mannyfernandez:~$
Shortcut Folder
I use a little utility that stays active in the menu bar of macOS. It allows me to pin files, folders, apps, scripts etc. I use it for our price list, my bio preso, product matrix, etc. These are files I use regularly and do not want to search for the files every-time.

The app costs about $5.00

You can click the + sign and then choose Add File/Folder

Then choose the file location

Now I can easily click on the INVENTORY link.
Recent posts
-
-
DNS is one of those technologies that quietly underpins... Full Story
-
BGP issues on FortiGate firewalls usually trace back to... Full Story
-
Every time your laptop talks to your router, a... Full Story
-
If you've spent any time configuring NAT on a... Full Story
-
If you have spent any time configuring firewall policies... Full Story
-
High availability on FortiGate is one of those features... Full Story
-
If you've configured SD-WAN on a FortiGate, you've almost... Full Story
-
FortiLink is the management protocol that turns a FortiSwitch... Full Story
-
FortiSwitches are pretty rock solid from Mean Time Between... Full Story
-
This is a quicky tip. Have you ever gone... Full Story
-
DNS is one of those quiet pieces of internet... Full Story
-
This article is an updated version of the previous... Full Story
-
You will add ns2 as a secondary (slave) BIND9... Full Story
-
In the process of deploying my lab, I needed... Full Story
-
RFC 8805, used to be known as Self-Correcting IP... Full Story
-
Years back, I wrote an article about certificate pinning. ... Full Story
-
FortiGates have the ability to send alerts to Microsoft... Full Story
-
In this post, I am going to walk through... Full Story
-
Troubleshooting VoIP on a FortiGate can feel like trying... Full Story
-
Prior to FortiOS 7.0, there were three commands to... Full Story
-
In this post, I am going to go over... Full Story
-
What we are going to do: We are going... Full Story
-
Choosing between FGCP (FortiGate Clustering Protocol) and FGSP (FortiGate... Full Story
-
Creating a VLAN on macOS (The "Pro" Move) A... Full Story
-
This blog post explores the logic behind how macOS... Full Story
-
Pretty Fly for a Wi-Fi Tell My Wi-Fi Love... Full Story
-
Part of my daily gig is creating BoMs (Bill-of-Materials)... Full Story
-
ICMP introduces several security risks, but careful filtering, rate... Full Story
-
The command diag debug application dhcps -1 enables full... Full Story
-
In the world of FortiOS, execute tac report is... Full Story
-
LLDP; What is it The Link Layer Discovery Protocol... Full Story
-
What it actually does When you run diagnose fdsm... Full Story
-
Monkey Bites are bite-sized, high-impact security insights designed for... Full Story
-
I have run macOS in macOS with Parallels but... Full Story
-
Don't be confused with my other FortiNAC posts where... Full Story
-
This is the third session in a multi-part article... Full Story
-
Today I was configuring key-based authentication on a FortiGate... Full Story
-
Netcat, often called the "Swiss Army knife" of networking,... Full Story
-
At its core, IEEE 802.1X is a network layer... Full Story
-
In case you did not see the previous FortiNAC... Full Story
-
This is our 5th session where we are going... Full Story
-
Now that we have Wireshark installed and somewhat configured,... Full Story
-
The Philosophy of Packet Analysis Troubleshooting isn't about looking... Full Story
-
Executive Summary A FortiGate is only as flexible as... Full Story
-
1. Title & Executive Summary Objective: This guide explains... Full Story
-
1. Title and Executive Summary Title: Power over Ethernet Standards... Full Story