2

I am looking to make a Python script that runs on whenever an email is received. In Windows Task Scheduler, I can set up a trigger for "On an event", using the Application log and "Outlook" as the source. However, I do not know what the Event ID for a new incoming email is. I've been Googling around for a while and haven't found anything likely because I don't know the correct search terms. Perhaps someone here knows where to look, or better yet, the answer directly?

Not sure if it matters, but I'm running Windows 7, 64-bit with Outlook 2010. Thanks in advance

EDIT: I'm assuming that there is one single event ID that is generated when an email is recieved. That ID (or where to find it) is what I'm looking for. If this is not the case, and there is no single ID which corresponds to an incoming email, then any work around y'all can think of would be great

EDIT: To avoid the XY problem, the goal here is to figure out a way to have a python script run upon receiving an e-mail..

Another, hopefully better, Edit: There are two main things I'm trying to do:

I have a Python script which handles a form which my entire office uses (~30 people). This form sends emails to various people around the office. It would be nice if it didn't just blindly send emails into the ether, but rather received feedback. Things such as acknowledgement that the email was properly sent, and then read. This is goal 1.

Goal 2 is a bit more simple. Thanks to the wonderful regulations in my industry, we have to keep an insane amount of records for certain projects. This includes emails. So I would like to set up a list of clients/projects which need this treatment, so that when such emails are received, they can automatically be stored (probably as a pdf) or printed.

Hopefully this helps

18
  • I think you should be able to set up a rule in Outlook so that when an email is received, it runs a script. I'm not 100% sure what scripts you can run (I assume you're probably limited to VB) but you can probably create a script that writes a custom event to the log. You may even be able to create a script that talks directly to your python script. Commented Jan 8, 2014 at 23:33
  • Although the Rules Wizard refers to the custom code as "script," you must create the code in Outlook Visual Basic for Applications, not in Microsoft Visual Basic Scripting Edition (VBScript) or other scripting languages such as Microsoft JScript. Also, Outlook Visual Basic for Applications is not designed to be deployed, so deployment of this custom code requires manual configuration on each user's computer. Source: support.microsoft.com/kb/306108 Commented Jan 8, 2014 at 23:35
  • 1
    Well you can perhaps handle it through VBA macro in outlook itself. VBA can do a lot of things outside domain of its parent application as well. Why are you specifically looking for external script? Commented Jan 9, 2014 at 17:16
  • 1
    There's definitely an ID for every mail, it's a very long string and is written in different formats. This has nothing to to with an Event ID from the event viewer logs. What is your mail backend, Exchange server? Have you looked at its APIs? Show some things that you have tried, what information did you manage to receive? A complication may also be having to distinguish new/modified events.
    – Jan Doggen
    Commented Jan 14, 2014 at 14:42
  • 1
    If the form sends emails within your company, then why even assume it wasn't delivered? Either way, if it was delivered would be most optimally checked on your mail exchange server, which knows when it places the email into the users mailbox. Solutions in regards to archiving email would also best be implemented on the mail exchange server in my opinion. Commented Jan 14, 2014 at 15:43

3 Answers 3

0

This is a quick description of something that may help you. Not totally sure you can access this event from python, looks like it might be a .net feature. Hopefully it sends you down the right path.

expression .NewMailEx(EntryIDCollection)

1
  • Sorry, I guess I was a little unclear, I'm not trying to get at it through Python, I just want to give the value to task scheduler
    – wnnmaw
    Commented Jan 7, 2014 at 1:14
0

Sadly, I only have a German Outlook installation here at work, so I can't provider proper screenshots. Here's what you're going to want to do though.

  1. Create a new rule in Outlook.

  2. Create a rule without using a template and select that the rule should apply to messages being received.

  3. In the next step you're supposed to set the conditions for the rule, don't supply any and click Next.
    You will be asked if you're sure that you don't want to set any conditions, confirm.

  4. You can now select the actions to perform. You should select that you want to start an application. Then click the application link in the lower panel.

    Outlook wants you to point directly to an executable and won't let you supply arguments. So you're going to want to create a small batch file to start your Python script and point Outlook to that batch file.

  5. Set up any exceptions if you need them, then go to the final step.

  6. Now name your rule and save it. It will now invoke your Python script every time you receive an email.

By the way, there is no event ID for received emails. To find an event ID, just check the Application log in the Event Viewer. Outlook does not log received messages to the event log.

11
  • Is there a way I can do this from the command line? This would allow me to hand out a batch file to everyone in the office
    – wnnmaw
    Commented Jan 14, 2014 at 14:49
  • @wnnmaw You can programmatically create Outlook rules, but I've never done that. Commented Jan 14, 2014 at 14:53
  • This was the advantage of the general task scheduler, I can get at it from cmd.
    – wnnmaw
    Commented Jan 14, 2014 at 15:02
  • By the way, if you're trying to run a Python script for every received email on every workstation of employees in the company, then it's probably still an XY problem ;) Commented Jan 14, 2014 at 15:06
  • 1
    @wnnmaw Because running a Python script upon receiving the email isn't your problem. Your problem is probably the one you're trying to solve with the Python script. Commented Jan 14, 2014 at 15:18
0

Right,

I believe what you can do is create a rule as @oliverSlazburg states, that runs a batch file.

In the batch file you can use the following syntax to write an event directly to the event logs:

eventcreate [/s Computer [/u Domain\User [/p Password]] {[/l {APPLICATION|SYSTEM}]|[/so SrcName]} /t {ERROR|WARNING|INFORMATION|SUCCESSAUDIT|FAILUREAUDIT} /id EventID /d Description

as per http://technet.microsoft.com/en-us/library/bb490899.aspx

Let me know how this goes.

6
  • Well I got somewhere. Here's my command (with some bits left out): eventcreate /s myIP /u myDomain\myUsername /p myPassword /l APPLICATION /so Outlook /t INFORMATION /id 999 /d "Custom event". And here's the result: Custom event"\n WARNING: Passing the user credential for local connection.\n ERROR: Source parameter is used to identify custom applications/scripts only (not installed applications).
    – wnnmaw
    Commented Jan 15, 2014 at 14:00
  • I assume you're using an admin account for this? UAC disabled? Commented Jan 16, 2014 at 20:51
  • Yep, I've got an admin account. What do you mean by "UAC"?
    – wnnmaw
    Commented Jan 16, 2014 at 20:54
  • User Account Control. The popups that come up when an admin action is required. I know it can cause issues at times. Commented Jan 19, 2014 at 20:12
  • Actually, looking at the result again it may be taking issue with you creating a custom event using the name of an installed app. try changing the /so to Outlook0 or something similar. Commented Jan 19, 2014 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .