简体   繁体   English

VSTO Outlook Addin:Application_ItemSend参数中的有线Item对象

[英]VSTO Outlook Addin: wired Item object in Application_ItemSend arguments

I wrote a simple VSTO addin for Outlook 2016(part of office 365) to check if there is some email addresses outside our company are mixed in the recipients list. 我为Outlook 2016(办公室365的一部分)编写了一个简单的VSTO插件,以检查我们公司外的某些电子邮件地址是否在收件人列表中混合。 I simplified the code like below: 我简化了如下代码:

      int countExternalAddress;
      string externalAddresses;
      string internalDomain=“@example.com”; 
     //indicates the email domain of our company, we use exchange server.

     private void Application_ItemSend(object Item, ref bool Cancel)
     {

        countExternalAddress = 0;
        externalAddresses="";

        Outlook.MailItem item = (Outlook.MailItem)Item;

        foreach (Outlook.Recipient recp in item.Recipients)
        {
             ConvertExchangeAddrToSMTPAddr(recp.AddressEntry.Address);
             //by access ExchangeUser.PrimarySmtpAddress
             CheckTheAddress(recp.AddressEntry.Address);
        }

        if (countExternalAddress > 0)
        {
           Warn();
        }

     }

The code works with no problem most of time, but some times Warn() function shows warnings based on (part of) the recipients of the LAST email, not the CURRENT one. 代码在大多数情况下都没有问题,但有时Warn()函数会根据最后一封电子邮件的收件人(部分)显示警告,而不是CURRENT邮件。 The problem cannot be reproduced all the time, but when it occurs, the procedure is like: 问题无法一直复制,但一旦发生,程序如下:

  1. Send an email to internal recipients(my colleagues, exchange addresses), the exchange addresses are successfully converted to SMTP address, because they are predefined as "internal" address, the mail will be sent without warning. 发送电子邮件给内部收件人(我的同事,交换地址),交换地址成功转换为SMTP地址,因为它们被预定义为“内部”地址,邮件将在没有警告的情况下发送。
  2. send another email to some other internal recipients, the program shows warning of "external address mixed", and the "external" address are from the previously sent email(mentioned in 1 above, not all addresses just one of them), and, the detected external address is in Exchange address format which is supposed to be converted to SMTP format. 发送另一封电子邮件给其他内部收件人,该程序显示“外部地址混合”的警告,“外部”地址来自先前发送的电子邮件(上面1中提到,并非所有地址只是其中一个),以及检测到的外部地址是Exchange地址格式,应该转换为SMTP格式。 Strangely, I cannot find the address in the recipients list of the current email. 奇怪的是,我找不到当前电子邮件的收件人列表中的地址。 If I save the current email and restart outlook, when I pick the saved email and try to resend it, no such "external" address will be detected again. 如果我保存当前电子邮件并重新启动Outlook,当我选择已保存的电子邮件并尝试重新发送时,将不会再次检测到此类“外部”地址。

    It looks like the Item object passed by ItemSend event contains some recipient(s) not only belong to the current email but also from the previously sent one, but they are not visible in the current email, moreover I cannot find such recipients in the sent email as well. 看起来像ItemSend事件传递的Item对象包含一些收件人不仅属于当前的电子邮件而且还来自之前发送的邮件,但它们在当前电子邮件中不可见,而且我在发送的邮件中找不到这样的收件人电子邮件也是。 The work PC I am using doesn't have debug environment so I am running out of means. 我正在使用的工作PC没有调试环境,所以我的手段已经用完了。 Please give me your helps, thanks in advance. 请提前感谢你,给我你的帮助。

Could it have anything to do with you doing > 它可能与你做任何事情>

if (countExternalAddress > 0) { Warn(); }

and not == 而不是==

if (countExternalAddress == 0)
    {
       Warn();
    }

Seems odd but it would leave one more email to warn you about. 看起来很奇怪,但它会留下一封电子邮件来警告你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM