开发者

How do I determine if an Exchange mail item is an auto reply message?

I have a .NET application that polls an Exchange email mailbox for new messages on a scheduled basis. Further processing happens when new messages are found in the email mailbox. I've encountered an issue with the processing when auto reply messages are received in the mailbox [e.g. auto reply rule, or Out of Office messages].

I need a C# solution to determine if an Exchange mail item is an auto reply message. Is there an at开发者_如何学Gotribute on the mail item that indicates if the message is an auto response message?


Look for the existence of the header:

X-Auto-Response-Suppress

That is the flag Exchange adds to automated messages to prevent them from triggering other automated messages. That sounds like your exact use case. There are specific flags that can be set, but in my case I just didn't send replies no matter which flags were set.


The auto response information forms part of the header, and sometime the subject and body. It all depends of the server that did the auto response.

I personally use a 3rd party component to assist with the parsing of the emails. It is called ListNanny.

It has a parser engine, and a definition file, and can assist with some additional NDR types, such as Hard and Soft Bounces, ChallengeVerification, DnsError emails, and more.

If I get an "Unknown" type back using ListNanny, I then assume it is a correct email

Hope this helps

EDIT:

After the comment. My other suggestion would be to generate a couple of different types of Auto Respond messages.

From there you view the headers of the emails manually, find any entries that might indicate that it is an Auto Respond message (which does not appear on normal message), and then write your own email parser to if an email contain any of those Auto Respond 'signature', and then flag it as such.

I can only tell you that when you start off you'll most probably have a lot of False-Positives, or Positive-False emails, but this will get better after a while, and after you've processed more emails and refined your signature.

Sorry i couldn't have been more of assistance to provide you with code samples or other ideas.


After struggling with this problem for a while I decided to just use the simplest approach possible.

By using the Exchange web service (exchange.asmx) that is available to Exchange 2007 I decided to just check the subject line of each mail item to see if it contained "Out of Office" before continuing through the processing logic. All of the messages that I was dealing with were auto-reply messages that contained the "Out of Office" subject line.

I'm sure that I'll come across additional use cases of auto-reply messages that do not have "Out of Office" that I'll have to account for in the future. At that time I'll either modify the code to check the subject line against an array of possible subject lines, or continue searching for some additional attribute on the mail item that indicates an auto reply message.

I'm pretty sure that additional attribue is the "Return-Path:" value in the header of the mail item, but I haven't found an easy way to get that attribute. From what I can tell, if the "Return-Path" has a "<>" value, it is an auto reply message otherwise it would have a valid email address.


It seems if you're using the Exchange EWS managed API, you can check the ItemClass of the Exchange "item". This indicates if it's a Task, Event, Document, Email, etc.

It also indicates if it's an OofTemplate or NDR (bounce). Some of the classes are listed here:

https://learn.microsoft.com/en-us/office/vba/outlook/Concepts/Forms/item-types-and-message-classes

So the basic idea would be to check...

if(item.ItemClass != "IPM.Note")

... then it's not an email and/or it's an auto-reply


Yes, there is an attribute but it's called InternetMessageHeaders and it's not just one as we have multiple Email Exchange server and they follow there own standard.

Here is the list of headers that can be checked:

Auto-Submitted: auto-replied
X-Auto-Response-Suppress:all
Precedence: auto_reply
X-Autoreply: yes
Auto-Submitted: auto-generated
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜