我编写了一个程序,当单击按钮时,该程序应该会收到收件人电子邮件。当我使用mailItem.Save()但它可以工作时,它可以复制收件人并将其保存到我不想发生的草稿文件夹中。
有什么方法可以调用“检查名称”功能?还是应该怎么做才能获得所有收件人,而不是使用mailItem.Save()?
过程:
摘要:
//CC account manager when this button is clicked
private void uxCcManager_Click(object sender, RibbonControlEventArgs e)
{
//check if user is authorized to use this feature
if (!CheckAuthorization())
{
return; // Authentication failed do not proceed any further
}
//save mail items entered in fields else they will get overidden by space
mailItem.Save();
mailItem.Recipients.ResolveAll();//check recepent name
if (mailItem != null)
{
//check if EntryID (unique id passed as a parameter of the event) of the currentItem not null.
//the entry id changes when an item is moved from folder to folder(drafts->outbox->Sent Items).
if (mailItem.EntryID != null)
{
if (mailItem.To == null)
{
MessageBox.Show("Please, enter the email address that you're sending email to!");
}
else if (mailItem.To != null)
{
//get individual emails from mailItem.To for the purpose of getting indivdual account manager
if (!IndividualRecipent(mailItem.Recipients))
{
MessageBox.Show("Cannot identify one or more emails, please check names and try again.");
}
}
}
}
}
答案 0 :(得分:0)
我在https://social.msdn.microsoft.com/Forums/en-US/a7ba3272-1e1e-4601-a183-e63cd15ceea4/outlook-couldnt-recognize-recipients-in-compose-mailitemto-when-button-clicked?forum=outlookdev的MSDN论坛上对您的问题的答复的副本
请勿使用“收件人”属性(以及CC和BCC)-保存邮件时,它们仅由商店根据收件人表进行更新。更糟糕的是,您仅检查“收件人”收件人,但是仅发送给CC或BCC收件人是完全合法的。更糟糕的是,“收件人/抄送/密件抄送”属性通常仅包含显示名称,而不包含电子邮件地址。
使用MailItem.Recipients集合,遍历它,对于每个收件人对象,检查Address和Name属性。