This macro is made for a opsmgr management pack, soon to be published on this blog.
It is written in VBA in outlook 2010 (could work in other version too, but it is not tested).
It shows how to create a macro function, that is usable in a rule.
1. Enable Developer Ribbon to be able to create scripts
2. Open visual Basic
3. Select “ThisOutlookSession”
4. Type/ this Sub into Visual Basic. Changed the strExportPath to the folder you want to use.
Sub SaveMessageOnRule(Item As Outlook.MailItem) Dim strExportPath As String strExportPath = "C:\Temp\Mails\" Dim FileName As String FileName = strExportPath & Replace(Replace(Replace(Now & "_" & Item.EntryID & ".txt", ":", "_"), "-", "_"), " ", "_") 'Create filename and path, replace : with _, - with _ and space with _. Dim FileNum As Integer FileNum = FreeFile ' next file number Open FileName For Output As #FileNum ' creates the file if it doesn't exist Print #FileNum, Item.Body ' write information at the end of the text file Close #FileNum ' close the file End Sub
5. Create rule in outlook
6. Select the coditions you want. Or none to process all emails
7. Select “run as Script” in the Select actions window, and choose the sub you have just created
8. Define exceptions if you have any, otherwise leave it blank.
9. Give your rule a name and save it.
10. You are now ready to setup the managementpack
Det er da for cool en stump kode at bruge til sin regel. Jeg kan forestille mig et par steder, hvor dette er super smart. Jeg har selv tidligere brugt dette med kode og regler i forbindelse med autosave af attachments – det fungerer også ret fedt.
Hi – I have tried the code above but does not work – not doing anything…
Is there anything I need to install in order to get this to work?
Thanks,
Ruan
hello Ruan
We are running this macro in several customer setups and have never had problems.
There is nothing more needed than described here.
I am not sure what problem you have, but you must have some mistake somewhere
or you might have security settings that does not allow the macro to be executed.
have a nice day
Hi,
Sorry, but this doesn’t work for me either.
Run-Time error 76: Path Not Found.
With the highlighted part (after I select Debug):
Open FileName For Output As #FileNum ‘ creates the file if it doesn’t exist
I don’t know VBA so not sure what else to change – I only change the Export Path. Want to save the daily emails to a new txt file every day, preferably with email subject+timestamp as name.
Hello Gerhard
I am sorry to hear that it does not Work.
your problem with the Path can be a lot of different issues.
1. Are you referring to a folder that is 64bit and running at 32bit office? (c:program files etc)
2. Can be access permission problem
3. Other stuff (error in path, using environment variables that does not exist etc %TEST%
To change the VBA, you will have to learn how to write it. I cannot give you an example here, but you are welcome to order the work done from Coretech, just email me and I can send you an estimate 🙂
I don’t know whether it’s just me or if perhaps everybody else encountering issues with your blog.
It looks like some of the text on your content are running off the screen.
Can somebody else please provide feedback and let me know
if this is happening to them as well? This could be a issue with
my web browser because I’ve had this happen before. Thanks
FYI – the runtime error people are talking about is occurring for me due to a fault in the filename – caused by the “now” command.. It appears to be trying to save it in date format including forward slashes which bugs it up (you can see what it will be called by hovering over the “filename”) – take the “now” out or set the date format correctly to get it working.
File permissions will bring up a different error code.
It worked perfectly in our environments, our date format does not have slashes in it.
If you are running US locale, you might get the issue you are talking about.
This is just a Proof of concept, and not a production implementation.
and yes a module or a transport agent, or plenty of other solution is possible, but not as simple as this one.
but thank you for letting others know 🙂
^^^ALso – your probably better off setting this as a Module instead of outlook session, that way the code can be customised for different variations and still applied via the rule method.
Virkede fint for mig. Har selv brugt det tidligere. Det er sindsygt smart. Alt andet ville være bøvl.