Outlook 2010: Auto Export Body of new e-mails

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

clip_image002

2. Open visual Basic

clip_image003

3. Select “ThisOutlookSession”

clip_image004

4. Type/ this Sub into Visual Basic. Changed the strExportPath to the folder you want to use.


5. Create rule in outlook

clip_image005

6. Select the coditions you want. Or none to process all emails

clip_image007

7. Select “run as Script” in the Select actions window, and choose the sub you have just created

clip_image009

8. Define exceptions if you have any, otherwise leave it blank.

clip_image011

9. Give your rule a name and save it.

clip_image013

10. You are now ready to setup the managementpack

By | 2017-08-21T21:17:06+00:00 March 28th, 2011|Scripting & Development|10 Comments

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (http://mvp.microsoft.com/en-us/default.aspx), Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at http://blog.ctglobalservices.com/jgs

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (www.mmsmoa.com)
  • SCU Europe 2014, 2015, 2016 (www.systemcenteruniverse.ch)
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (www.nic.com)
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (www.techdays.se)
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack

Training:

  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops

10 Comments

  1. Jens Hansen October 18, 2011 at 18:46 - Reply

    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.

  2. Ruan October 9, 2012 at 10:46 - Reply

    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

    • Jakob Gottlieb Svendsen
      Jakob Gottlieb Svendsen October 9, 2012 at 11:09 - Reply

      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

  3. Gerhard January 18, 2013 at 8:49 - Reply

    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.

    • Jakob Gottlieb Svendsen
      Jakob Gottlieb Svendsen January 18, 2013 at 12:35 - Reply

      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 🙂

  4. 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

  5. Terry July 1, 2013 at 23:56 - Reply

    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.

    • Jakob Gottlieb Svendsen
      Jakob Gottlieb Svendsen July 2, 2013 at 9:23 - Reply

      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 🙂

  6. Terry July 1, 2013 at 23:59 - Reply

    ^^^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.

  7. Tim Janson April 7, 2015 at 8:58 - Reply

    Virkede fint for mig. Har selv brugt det tidligere. Det er sindsygt smart. Alt andet ville være bøvl.

Leave A Comment