【问题标题】:Outlook could't recognize recipients when button clicked单击按钮时 Outlook 无法识别收件人
【发布时间】:2018-08-23 18:19:02
【问题描述】:

我编写了一个程序,当单击按钮时应该会收到收件人电子邮件。当我使用 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.");
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# outlook


    【解决方案1】:

    我在 MSDN 论坛 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 上对您的问题的答复的副本

    不要使用 To 属性(以及 CC 和 BCC) - 它们仅在保存邮件时由存储根据收件人表更新。更糟糕的是,您只检查收件人,但仅发送给 CC 或 BCC 收件人是完全合法的。更糟糕的是,To/CC/BCC 属性通常只包含显示名称,而不包含电子邮件地址。

    使用 MailItem.Recipients 集合,遍历它,并检查每个 Recipient 对象的 Address 和 Name 属性。

    【讨论】:

      猜你喜欢
      • 2011-11-02
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多