I've wrote a custom transport agent that overrides the routing of the FROM user to make it go to specific send connectors. The reason is because there are certain people I want going out specific send connectors for smart host options such as email archiving/encryption.
Now the problem I'm facing is when I do this with a smart host it works great! But if I remove the smart host and let Exchange do DNS lookups then it will **sometimes** get the 5.4.4 NonExistent Domain errors.
So I have a send connector with the address space set to "custom-domain1xyz.com" which is just a fake domain we use for one send connector. I override the messages which force it to go out that send connector. My guess is Exchange is looking up the custom-domain1xyz.com instead of doing an actual lookup on the receipient domain.
This is the override code in C# for OnResolvedMessage event:
foreach (var recipient in e.MailItem.Recipients) { RoutingDomain newRoutingDomain = new RoutingDomain("custom-domain1xyz.com"); RoutingOverride newRoutingOverride = new RoutingOverride(newRoutingDomain, 0); source.SetRoutingOverride(recipient, newRoutingOverride); }
The value 0 should be UseOverrideDomain: https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.data.transport.deliveryqueuedomain(v=exchg.150).aspx
Here is the override method:
https://msdn.microsoft.com/en-us/library/office/dd899758(v=exchg.150).aspx