If you are one of those people who is too lazy to download attachments from their email (me!), this script is perfect for you!
All you need is:
- A machine that is constantly running
- Microsoft Outlook
Let’s get to it:
For this example, I am going download/save “Outside Pittsburgh IP Alert” log reports that are sent from “Administrator” to my email on a daily basis. These reports will be saved in C:\Users\anindayu.pradetha\Downloads\Log Report\
- Go to Visual Basic in the Developer tab or press Alt + F11.
- Click Insert > Module and paste the VB script below into the Module window:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = “C:\Users\anindayu.pradetha\Downloads\Log Report\”
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Note: Replace “C:\Users\anindayu.pradetha\Downloads\Log Report\” with the path of the destination folder that you desire.
- Save the script and close the VB window.
- In the Home tab, click Rules > Management Rules & Alerts.
- Then, click New Rule button on the E-mail Rules tab.
- In the Rules Wizard box, select Apply rule on messages I receive, and click Next.
- In the (Which condition(s) do you want to check?) dialog box, check any option that applies to you. In my case, to ensure that the attachments from all emails that are entitled “Outside Pittsburgh IP Alert” and sent by Administrator will be saved in the desired folder, I will check with specific words in the sender’s address and with specific words in the subject or body and add the specific words for each option. Click Next when you are done.
- In the (What do you want to do with the message?) dialog box, check the run a script option, select the a script option, and add Project1.SaveAttachmentsToDisk. Then, click Next.
Can’t find the “run a script” option? Visit this page for more info on how to enable the option.
- In the (Are there any exceptions?) dialog box, click Next.
- In the last dialog box, name the rule that you desire. check Run this rule now on messages already in “Inbox” and Turn on this rule options, and click Finish.
- Close the Rules and Alerts dialog box.
Tada! Now all attachments from emails that are sent from Administrator with the subject Outside Pittsburgh IP Alert will be saved directly to the specified destination folder.