1

We have an Exchange Trasport Agent, which is specifically a RoutingAgent. In the OnSubmittedMessage event we need to inspect the MailItem and determine if it is outbound or inbound. I am currently looking at using the SmtpServer.AcceptedDomains property to check if the sender email is in the accepted domains list. Here is an example of how we are trying to do this:

private bool IsOutbound(MailItem mailItem, AcceptedDomainCollection acceptedDomains)
{
    if (acceptedDomains.Find(mailItem.FromAddress) != null)
    {
        return true;
    }
    return false;
}

I am not extremely familiar with Accepted Domains, and I am trying to understand if this is a viable solution to reliably determine the direction of an email? This scenario also needs to work for companies that have multiple domains included in their Exchange organization setup. Note that we plan to support Exchange 2010-2016 if that makes any difference.

--EDIT--

After getting some help from @GlenScales I realize I need to update my question a bit.

My goal is to determine if the sender of the email is in a domain that is internal to the Exchange organization. This could also be achieved by determining if the email was generated within Exchange, we are able to inspect the recipients at a later stage just fine and see if it is inbound or outbound.

With that being said, we looked at 3 possible solutions:

  1. Check the sender domain against the list of Accepted Domains
  2. Use the AddressBook to check if the sender is internal
  3. Check the InboundDeliveryMethod property and see if it was created from a mailbox

In the end we decided that we really wanted to be inspecting messages that were generated from a mailbox only and went with #3. #1 sounded like it could potentially include domains that were really just "forwarding" domains, and we do not want to consider those messages in our application.

cjablonski76
  • 173
  • 1
  • 13

1 Answers1

0

AcceptedDomains tells you all the SMTP domains that the Exchange Organization will delver for. Eg When the Exchange Transport Server performs message categorization on a Message if the Message is To an Address that is within the Accepted domains it will take responsibility for delivery that message to that recipients (there can be multiple recipients in a message so that point the message maybe forked and delivered to the Internal recipient and the sent on to the external recipient).

What your doing just tells you where the Sender is from not really the direction of the Message as such. OnSubmittedMessage means you capturing a Message before any categorization has taken place in the case it's a message that has been sent from within your org but if the message has both internal and external recipients some copies the it will have multiple destinations.

There also some other options in https://social.msdn.microsoft.com/Forums/en-US/9387e62a-76d7-4340-b9cc-f87ffcfab8b1/how-to-detect-the-message-source-in-an-exchange-server-2013-transport-agent-for-getting-the-sending?forum=exchangesvrdevelopment which I'd suggest you look at

Cheers Glen

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • I guess I am not really trying to determine the direction of the message now that I read your points, rather we are confirming that the sender of an email is internal to the Exchange org. We want our agent to do processing on any emails that are being sent from an internal Exchange Server. We originally were using the header you suggested in the link, "X-MS-Exchange-Organization-MessageDirectionality," for this but Microsoft ended up suggesting we try Accepted Domains instead, and I don't have any details on why from them yet. – cjablonski76 Apr 28 '16 at 20:33
  • Another alternative then would be the address book class https://msdn.microsoft.com/en-us/library/microsoft.exchange.data.transport.addressbook.isinternal(v=exchg.150).aspx you can validate the sender eg type and see if its internal. AcceptedDomains maybe the best performing if your doing high volume – Glen Scales Apr 28 '16 at 22:53
  • Thanks so much for this info, I had not ran into AddressBook yet, I have a couple questions to this: 1. Does AcceptedDomains end up achieving the same thing that AddressBook.IsInternal() would be getting me? I tested and saw that AddressBook.IsInternal() returned true for the fake test domain I added to AcceptedDomains. 2. What is AddressBook.IsInternal() doing that would make AcceptedDomains a faster approach? – cjablonski76 Apr 29 '16 at 20:20
  • 3. Do you have any documentation on AddressBook.IsInternal(), the microsoft site doesn't even have a generic message for it, just blank. Thanks again for all the help, I just want to choose the best possible option. – cjablonski76 Apr 29 '16 at 20:27
  • The addressbook allows you to validate the Address against the directory where accepteddomains just looks at the domain. It really comes down to what your trying to do, the enviroment, and if all your senders are in the directory, subdomains etc. MSDN and Transport SDK are the only documentation source there are, the best thing I can recommend is test it yourself. (eg maybe isInternal isn't what you looking for the AddressBook can be used to determine a number of other things) and maybe you use both eg http://www.getcodesamples.com/src/9345163/B476972E a good example – Glen Scales Apr 30 '16 at 01:38