2016-07-18 118 views
0

我为了业务目的制作了一个Outlook加载项(Outlook 2013和2016 VSTO加载项),以将电子邮件详细信息保存到我们的数据库。当一个新的电子邮件被组成时,加载项被启动,但当电子邮件被发送时关闭。c#Outlook加载项获取发送邮件后的发送日期发送邮箱

电子邮件的发送日期只有在电子邮件被移动到发送邮箱后才会添加。有没有方法可以使用我当前的加载项(或另一个加载项)在关闭之后获取该发送日期,而不让用户等待它移至发送的邮箱?

我知道它可以很容易地在VBA中完成,但我希望最好使用加载项,以便它可以轻松加载到所有使用交换服务器的用户。

回答

0

那不会是今天的日期/时间(现在)还是其他的东西?

您可以在VBA中执行的所有操作都可以在COM插件中执行 - 订阅已发送邮件文件夹中的Items.ItemAdd事件并检索事件触发时的日期。

0

谢谢德米特里的回复。它使我走上了正确的道路。将新项目添加到发送邮箱时,我使用现有的VSTO插件触发。我不知道在“ThisAddIn_Startup”方法中插入这个方法时,重新激活加载项,现在这是有道理的。我跟着this的例子。

这里是我的代码:

Outlook.NameSpace outlookNameSpace; 
Outlook.MAPIFolder Sent_items; 
Outlook.Items items; 

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{ 
    outlookNameSpace = this.Application.GetNamespace("MAPI"); 
    Sent_items = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail); 

    items = Sent_items.Items; 
    items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd); 
} 

void items_ItemAdd(object Item) 
{ 
    Outlook.MailItem mail = (Outlook.MailItem)Item;  

    string strMailItemNumber_filter = mail.UserProperties["MailItemNumber"].Value; 

    if ((Item != null) && (!string.IsNullOrWhiteSpace(strMailItemNumber_filter))) 
    { 
     if (mail.MessageClass == "IPM.Note" && 
        mail.UserProperties["MailItemNumber"].Value.ToUpper().Contains(strMailItemNumber_filter.ToUpper())) //Instead of subject use other mail property 
     { 
      //Write 'Sent date' to DB 
      System.Windows.Forms.MessageBox.Show("Sent date is: "+ mail.SentOn.ToString()+ " MailNr = "+strMailItemNumber_filter); 

     } 
    } 

} 

我必须创建新的邮件用户定义的属性相匹配我派人找到的邮箱发送了正确的电子邮件的电子邮件:

 private void AddUserProperty(Outlook.MailItem mail) 
    { 
     Outlook.UserProperties mailUserProperties = null; 
     Outlook.UserProperty mailUserProperty = null; 
     try 
     { 
      mailUserProperties = mail.UserProperties; 
      mailUserProperty = mailUserProperties.Add("MailItemNrProperty", Outlook.OlUserPropertyType.olText, false, 1); 
      // Where 1 is OlFormatText (introduced in Outlook 2007) 
      mail.UserProperties["MailItemNumber"].Value = "Any value as string..."; 
      mail.Save(); 
     } 
     catch (Exception ex) 
     { 
      System.Windows.Forms.MessageBox.Show(ex.Message); 
     } 
     finally 
     { 
      if (mailUserProperty != null) Marshal.ReleaseComObject(mailUserProperty); 
      if (mailUserProperties != null) Marshal.ReleaseComObject(mailUserProperties); 
     } 
    } 
相关问题