How do I find the Event ID for an incoming email?

2

0

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

wnnmaw

Posted 2014-01-06T22:20:23.137

Reputation: 237

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. – Miles Hayler – 2014-01-08T23:33:47.060

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: http://support.microsoft.com/kb/306108

– Miles Hayler – 2014-01-08T23:35:19.180

@MilesHayler There's no direct trigger for a received email, only the method I describe above. As for running the script, I can definitely directly run python – wnnmaw – 2014-01-08T23:37:09.830

@MilesHayler I understand the confusion, I'm working with windows task scheduler, which is independent of Outlook – wnnmaw – 2014-01-08T23:38:09.897

1Well 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? – tumchaaditya – 2014-01-09T17:16:25.650

There are a couple things in looking to do, the biggest is to get feedback that emails are sent correctly by another python script. Also, automatic printing /filing based on the sender would be nice – wnnmaw – 2014-01-09T18:01:29.067

I meant what @tumchaaditya said. You can probably write events directly to the event log with a script. – Miles Hayler – 2014-01-12T00:40:06.003

@MilesHayler How would I do such a thing? – wnnmaw – 2014-01-13T14:19:09.137

Why are you trying to do this through task scheduler? A new message in Outlook doesn't normally generate any events that can be captured in task manager. What are you really trying to do?

– Zoredache – 2014-01-13T17:39:01.270

@Zoredache, Thanks for pointing that out, see my edit. I defaulted to task scheduler because I didn't know there were alternatives – wnnmaw – 2014-01-13T17:46:31.840

Something like http://stackoverflow.com/questions/11263483/how-do-i-trigger-a-macro-to-run-after-a-new-mail-is-received-in-outlook perhaps? That just builds the VBA event. Then maybe toss in this for launching your python app if you don't want to do your work in VBA. http://stackoverflow.com/questions/6767445/how-to-launch-one-other-program-with-vba-code

– Zoredache – 2014-01-13T17:49:06.587

1There'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 – 2014-01-14T14:42:44.603

And this may turn out to be a programming question, in which case it has to move to StackExchange. – Jan Doggen – 2014-01-14T14:44:24.517

@JanDoggen, Once I figure out how to trigger my script, I can do everything else. Unfortunately, I have no progress to show what I've done aside from what I've already written. And yes, I'm pretty sure this is on an Exchange server – wnnmaw – 2014-01-14T14:48:40.440

And have you looked at the Exchange APIS like EWS? IIRC they have notifications. No idea though how hard that would be to handle from Python. Advantage is that it would take Outlook out of the loop. – Jan Doggen – 2014-01-14T15:05:55.787

BTW I think your second edit is incomplete. You want to do something with that mail. – Jan Doggen – 2014-01-14T15:07:09.060

Frist comment: I haven't looked into those. Right now I'm looking into writting a python script which an implement Outlook rules as per Oliver's answer. Second comment: Yes, I know how to do that processing once I get into a Python – wnnmaw – 2014-01-14T15:16:43.597

1If 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. – Der Hochstapler – 2014-01-14T15:43:31.943

Answers

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)

CodeMonkey

Posted 2014-01-06T22:20:23.137

Reputation: 1 255

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 – 2014-01-07T01:14:26.100

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.

Der Hochstapler

Posted 2014-01-06T22:20:23.137

Reputation: 77 228

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 – 2014-01-14T14:49:16.677

@wnnmaw You can programmatically create Outlook rules, but I've never done that.

– Der Hochstapler – 2014-01-14T14:53:49.987

This was the advantage of the general task scheduler, I can get at it from cmd. – wnnmaw – 2014-01-14T15:02:17.167

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 ;) – Der Hochstapler – 2014-01-14T15:06:24.783

How so? I'm asking how to run a python script upon receiving an email. – wnnmaw – 2014-01-14T15:14:13.583

@wnnmaw AND you want to hand it out as a batch file to everyone in the office. So... yeah... XY-problem. (You didn't specify you wanted this for more/all your computers. If you have a common server for example you could do this much easier, you also didn't specify what the python script does. Maybe that can also be done differently). – Rik – 2014-01-14T15:16:24.137

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. – Der Hochstapler – 2014-01-14T15:18:37.427

@Rik, sure, I should have included that in the question, but that's not what an XY problem is (as I understand it). And how might I do this with a common server? – wnnmaw – 2014-01-14T15:19:38.160

@OliverSalzburg, Ok, I see where you're coming from. I would consider this a sub-problem of a larger problem. If that makes this an XY, then I appologize – wnnmaw – 2014-01-14T15:22:19.657

@wnnmaw It's exactly what a XY-problem is. You're trying to do something with a python script (we don't know what) and you ask help with running the script not knowing we might have a much better solution than what you are trying to do with that python script. The XY problem is asking about your attempted solution rather than your actual problem

– Rik – 2014-01-14T15:22:30.873

@Rik and Oliver, please see my revised post – wnnmaw – 2014-01-14T15:30:16.807

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.

Miles Hayler

Posted 2014-01-06T22:20:23.137

Reputation: 209

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 – 2014-01-15T14:00:44.147

I assume you're using an admin account for this? UAC disabled? – Miles Hayler – 2014-01-16T20:51:21.863

Yep, I've got an admin account. What do you mean by "UAC"? – wnnmaw – 2014-01-16T20:54:37.990

User Account Control. The popups that come up when an admin action is required. I know it can cause issues at times. – Miles Hayler – 2014-01-19T20:12:26.717

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. – Miles Hayler – 2014-01-19T20:14:22.820

I can confirm this does work (although i don't have Outlook installed) and you can send an event to another computer. I don't think you have some use for it because the other computer won't have access to the mail (it only sees the event) and knowing what you want to use it for. If the other computer does have access to the mail you could do this a whole other way. If it is not to send an event to another computer but to this computer itself you don't need to use events and you can start your python script directly from the batch-script. – Rik – 2014-01-20T09:53:04.903