Exchange - 将电子邮件消息的收件人从通讯组类型更改为来自其成员的单个电子邮件地址的路由代理

Exchange - routing agent that changes the email massage's recepient from a distribution group type to single email adresses from its members

我正在使用 c#(框架 3.5)为 exchange 2010 构建路由代理 我有一个接收电子邮件的第三方应用程序,并通过他们的电子邮件地址对用户进行身份验证。

问题是在我向通讯组发送电子邮件时出现的, "To" 字段设置为 D 组电子邮件地址,这导致我在使用第 3 方应用程序时出现问题。

如何转换发送至 xxxGroup@xxx.com

的电子邮件消息的收件人字段

进入:user1inGroup@xxx.com;user2inGroup@xxx.com,..

这是我的代码的一部分,我尝试删除 "to" 字段,但似乎没有任何效果。

void ownRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs messageEventArgs)
      {
          bool forwardToSeg = false;

          if (true) EventViewerLogger.WriteInfo("FromAddress: " + messageEventArgs.MailItem.FromAddress.ToString());
          if (true) EventViewerLogger.WriteInfo("SecureSenders: " + m_SecureSenderAddress);

          distGroupList = generateDistGroupList();


                  ////////////////////////////////////////////
                  //Check if recepient is a distrebution group

                  Random rnd = new Random();
                  int numOfUser = rnd.Next(0, senderAddresses.Length);
                  messageEventArgs.MailItem.FromAddress = new RoutingAddress(senderAddresses[numOfUser]);

                  // run over all recipients list
                  //foreach (EnvelopeRecipient recp in messageEventArgs.MailItem.Recipients)
                  //{
                  foreach (MyClass disGrp in distGroupList)
                  {
                      // Checks if Recipients contain an e-mail group.
                      // if yes, does not route to seg.
                      if (messageEventArgs.MailItem.Message.To[0].NativeAddress.ToString().ToUpper() == disGrp.emailAdress.ToUpper())

                      {
                          messageEventArgs.MailItem.Message.To[0].NativeAddress.Remove(0);
                          messageEventArgs.MailItem.Message.To.Remove(new EmailRecipient(messageEventArgs.MailItem.Message.To[0].DisplayName.ToString(),messageEventArgs.MailItem.Message.To[0].NativeAddress.ToString()));

                          foreach (EnvelopeRecipient yywx in messageEventArgs.MailItem.Recipients)
                          {
                              //remove group address from mail-recipients


                              //   messageEventArgs.MailItem.Message.To.Add*******
                              //       = messageEventArgs.MailItem.Recipients


                              //add all group members to the "TO" field


                              //messageEventArgs.MailItem.Recipients;

                          }
              }
          }

使用地址簿 class 执行此操作或在传输代理中展开邮件的收件人。如果您想扩展需要 AD 调用的列表,这在传输代理的性能方面可能非常昂贵。