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:
- Check the sender domain against the list of Accepted Domains
- Use the AddressBook to check if the sender is internal
- 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.