我想向分发群发送电子邮件,并确保收件人会收到特别发送给他们的电子邮件。 意思是:在" To"字段我希望他们只能看到他们的电子邮件地址,而不是粗体字母组的名称。
我正在为Exchange构建主题路由器dll,我需要将发送到组的电子邮件拆分为单独的电子邮件。 我正在使用Exchange 2010。 任何想法?
我想做这样的事情:
messageEventArgs.MailItem.Message.To = messageEventArgs.MailItem.Recipients
但不幸的是messageEventArgs.MailItem.Message.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();
// 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;
}
}
//}
}
}
答案 0 :(得分:1)
您可以从该组中获取电子邮件列表,然后发送邮件。以下代码段将获取各个邮件ID。
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
}
}
此外,您仍然可以使用单个邮件并将电子邮件地址保留在BCC字段中。不确定要求是什么..