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
57 }
58}
59
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
57 }
58}
59