opo 发表于 2015-9-13 13:25:22

VS2008开发Outlook 附件检查!

比较简单,没有什么好说的!
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Outlook = Microsoft.Office.Interop.Outlook;
5using Office = Microsoft.Office.Core;
6using System.Windows.Forms;
7
8namespace OutlookAddInAttachmentCheck
9{
10    public partial class ThisAddIn
11    {
12      private void ThisAddIn_Startup(object sender, System.EventArgs e)
13      {
14            //this.Application.ItemSend
15            this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
16      }
17
18      void Application_ItemSend(object Item, ref bool Cancel)
19      {
20            if( Item is Outlook.MailItem)
21         {
22                Outlook.MailItem myItem = (Outlook.MailItem)Item;
23               
24                if (myItem.Body.IndexOf("附件") > -1|| myItem.Body.ToUpper().IndexOf("ATTACHMENT")>-1)
25                {
26                  if (myItem.Attachments.Count == 0)
27                  {
28                        MessageBox.Show("请添加附件,因为您在邮件中提到附件!", "提醒!", MessageBoxButtons.OK);
29                        Cancel = true;
30                  }
31                }
32
33
34            }
35            
36      }
37
38      private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
39      {
40      }
41
42
43
44      VSTO generated code#region VSTO generated code
45
46      /**//// <summary>
47      /// Required method for Designer support - do not modify
48      /// the contents of this method with the code editor.
49      /// </summary>
50      private void InternalStartup()
51      {
52            this.Startup += new System.EventHandler(ThisAddIn_Startup);
53            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
54      }
55      
56      #endregion
57    }
58}
59
页: [1]
查看完整版本: VS2008开发Outlook 附件检查!