我正在使用c#(框架3.5)为Exchange 2010构建路由代理 我有一个第三方应用程序收到电子邮件,并通过他们的电子邮件地址验证用户。
当我向通讯组发送电子邮件时,问题就出现了, " To"字段设置为D组电子邮件地址,这会导致我的第三方应用程序出现问题。
如何将电子邮件按摩的TO字段转换为:xxxGroup@xxx.com
进入:user1inGroup@xxx.com; user2inGroup@xxx.com,.....
这是我的代码的一部分,我尝试删除"到"领域,但似乎没有任何作用。
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;
}
}
}
答案 0 :(得分:0)
使用AddressBook类执行此操作或在传输代理中展开邮件的收件人。如果你想扩展一个需要AD调用的列表,这在运输代理的性能方面可能非常昂贵。