Exchange - Splitting a distribution group

China☆狼群 提交于 2019-12-12 05:41:43

问题


I want to send an email to a distribution group, and make sure the recipients will get the email as it was send especially to them. meaning : in the "To" field I want them to see only their email address and not the group's name in bold letters.

I am building a subject router dll for Exchange, and I need to split emails sent to groups, to individual email messages. I'm working on Exchange 2010. any ideas ?

I want to do something like this:

messageEventArgs.MailItem.Message.To = messageEventArgs.MailItem.Recipients

but unfortunately messageEventArgs.MailItem.Message.To is read only...

Any other ideas ?

Here is some sample code as requested:

       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();

      // Change origional Sender EMail Address to a random sender from the list of SEG users
      foreach (string senderAddr in m_SecureSenderAddress.Split(','))
      {
          //Check if sender equals to a secure sender
          if (senderAddr.ToUpper() == (messageEventArgs.MailItem.FromAddress.ToString().ToUpper()))
          {
                 Random rnd = new Random();
                 int numOfUser = rnd.Next(0, senderAddresses.Length);
                 messageEventArgs.MailItem.FromAddress = new RoutingAddress(senderAddresses[numOfUser]);

                 forwardToSeg = true;

     //Check if recepient is a distrebution group

                 // run over all recipients list
                 //foreach (EnvelopeRecipient recp in messageEventArgs.MailItem.Recipients)
                 //{
                     // run over excluded members list
                     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.ToString().ToUpper() == disGrp.emailAdress.ToUpper())
                         {
                             messageEventArgs.MailItem.Message.To.Add*******
                                 = messageEventArgs.MailItem.Recipients
                             //create a method that extracts group members and saves them in an array
                             //delete group address from mail-recipients

                             //messageEventArgs.MailItem.Recipients;
                             return;
                         }
                     }
                 //}
           }
      }

回答1:


You can get the list of e-mails from the group and then send the mail. Following snippet will get the individual mail IDs.

    string groupName = "somegroup";
    string domainName = "somedomain";

    using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName))
    {
        using(GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName))
        {
            var sams = from x in grp.GetMembers(true) select new {x.SamAccountName, };
            var users = from sam in a.Distinct()
                let usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, sam)
                select new { usr.SamAccountName, usr.DisplayName, usr.EmailAddress};
            //users is now populated with the e-mail IDs
        }
    }

Additionally, you can still use a single mail and keep the email addresses in BCC field.. Not sure what the requirement is..



来源:https://stackoverflow.com/questions/37728507/exchange-splitting-a-distribution-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!