Answered by:
[E2010] [TA] [C#] [Windows] Transport Agent to determine if a message was/will be relayed externally. DeliveryMethod property doesn't appear sufficient.

-
I'm trying to write a Transport Agent that sends a count for externally relayed emails sent from our Exchange 2010 server. I can't seem to find a combination of properties that give an accurate count. I've tried
envelopeRecipient.OutboundDeliveryMethod == DeliveryMethod.Smtp
envelopeRecipient.RecipientCategory == RecipientCategory.InDifferentOrganization
If I send to only one internal, the result is 0, which is correct. If I send it to one external, the result is 1. Also correct. If I send it t one internal and one external, the result is 2 when it should be 1. If I send a message two internal mailboxes and one external, the result is 3 when it should be 1. etc.
What am I missing here?
public SyslogAgent()
{
// Register an OnRoutedMessage event handler
this.OnRoutedMessage += OnOnRoutedMessage;
}private void OnOnRoutedMessage(RoutedMessageEventSource source, QueuedMessageEventArgs queuedMessageEventArgs) { var extRecipients = 0; foreach (var envelopeRecipient in queuedMessageEventArgs.MailItem.Recipients) { if (envelopeRecipient.OutboundDeliveryMethod == DeliveryMethod.Smtp) extRecipients++; } if (extRecipients <= 0) return; var severity = (extRecipients > 20) ? Syslog.SeverityEnum.Alert : Syslog.SeverityEnum.Notice; try { Syslog.SendMessage(Syslog.FacilityEnum.Mail, severity, string.Format("{0} has sent a message to {1} external recipents via Exchange", queuedMessageEventArgs.MailItem.FromAddress.LocalPart, queuedMessageEventArgs.MailItem.Recipients.Count), "xxx.xxx.xxx.xxx", 514); } catch (InsufficientMemoryException ex) { Debug.WriteLine(ex.ToString()); } }
Justin Cervero - MS Enterprise Admin - Appalachian State University
- Edited by J Cervero Thursday, October 31, 2013 12:34 PM added code
Question
Answers
-
Using DeliveryMethod.Smtp wouldn't work if you have multiple AD sites and Exchange Hub servers in different sites. Hub Servers will use SMTP to communicate between sites.
I'd suggest you look at the EnvelopeRecipient.Properties http://msdn.microsoft.com/en-us/library/aa579279(EXCHG.140).aspx at debug time. Properties like Microsoft.Exchange.Transport.DirectoryData.RecipientType would indicate whether a recipient is Exchange Object like a Mailbox or PublicFolder etc.
The other thing is if all you want to do is count Outbound messages instead of doing this OnSubmit do it after Categorization (OnCategorizedMessage) when the Message has been forked (and any DL's have been expanded). That will give you a more true count of the Messages sent. You can also just get the same information for the Tracking logs.
Cheers
Glen- Marked as answer by J Cervero Thursday, October 31, 2013 1:32 PM
-
I found my bug. I'm a moron.
I forgot to change the value being sent the message from an earlier version of the code. I was sending the total recipient count instead of the calculated set of external addresses.
Justin Cervero - MS Enterprise Admin - Appalachian State University
- Marked as answer by J Cervero Thursday, October 31, 2013 1:32 PM
All replies
-
Using DeliveryMethod.Smtp wouldn't work if you have multiple AD sites and Exchange Hub servers in different sites. Hub Servers will use SMTP to communicate between sites.
I'd suggest you look at the EnvelopeRecipient.Properties http://msdn.microsoft.com/en-us/library/aa579279(EXCHG.140).aspx at debug time. Properties like Microsoft.Exchange.Transport.DirectoryData.RecipientType would indicate whether a recipient is Exchange Object like a Mailbox or PublicFolder etc.
The other thing is if all you want to do is count Outbound messages instead of doing this OnSubmit do it after Categorization (OnCategorizedMessage) when the Message has been forked (and any DL's have been expanded). That will give you a more true count of the Messages sent. You can also just get the same information for the Tracking logs.
Cheers
Glen- Marked as answer by J Cervero Thursday, October 31, 2013 1:32 PM
-
We only have a single server/site. I'm running it on the OnRouted event which takes place after the OnCategorized event. I'll update my code to reflect that for clarity.
I'll give the RecipientType a try.
Justin Cervero - MS Enterprise Admin - Appalachian State University
-
I found my bug. I'm a moron.
I forgot to change the value being sent the message from an earlier version of the code. I was sending the total recipient count instead of the calculated set of external addresses.
Justin Cervero - MS Enterprise Admin - Appalachian State University
- Marked as answer by J Cervero Thursday, October 31, 2013 1:32 PM