窝窝插件 发表于 2015-9-13 14:09:36

vsto outlook 检查附件大小

1 private Outlook.Explorer _Explorers;
2
3         private Outlook.Inspector _Inspectors;
4
5         double TotalAttachSize;
6
7         private void ThisAddIn_Startup(object sender, System.EventArgs e)
8
9         {
10
11            Outlook.Inspectors inspectors = this.Application.Inspectors;
12
13             inspectors.NewInspector +=
14
15               new Outlook.InspectorsEvents_NewInspectorEventHandler(
16
17               Inspectors_NewInspector);
18
19
20
21             foreach (Outlook.Inspector inspector in inspectors)
22
23             {
24
25               TotalAttachSize = 0;
26
27               Inspectors_NewInspector(inspector);
28
29             }
30
31   
32
33
34
35         }
36
37
38
39         void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
40
41         {
42
43             if (Inspector.CurrentItem is Outlook.MailItem)
44
45             {
46
47
48
49               Outlook.MailItem mail = (Outlook.MailItem)Inspector.CurrentItem;
50
51
52
53               mail.BeforeAttachmentAdd += new Microsoft.Office.Interop.Outlook.ItemEvents_10_BeforeAttachmentAddEventHandler(mail_BeforeAttachmentAdd);
54
55               mail.AttachmentAdd += new Microsoft.Office.Interop.Outlook.ItemEvents_10_AttachmentAddEventHandler(mail_AttachmentAdd);
56
57               
58
59             }
60
61      
62
63         }
64
65
66
67      
68
69
70
71         void mail_AttachmentAdd(Microsoft.Office.Interop.Outlook.Attachment Attachment)
72
73         {
74
75             int MB = 1024*1024;
76
77             MessageBox.Show(Attachment.Size.ToString() + "\n" + " Now Total Size limit reached is " + TotalAttachSize/MB + " MB");
78
79         }
80
81
82
83         void mail_BeforeAttachmentAdd(Microsoft.Office.Interop.Outlook.Attachment Attachment, ref bool Cancel)
84
85         {
86
87             TotalAttachSize =TotalAttachSize + Attachment.Size;
88
89             if (TotalAttachSize > (1024 * 1024 * 10 ))
90
91             {
92
93               MessageBox.Show("You have reached the total Attachment Size limit");
94
95               return;
96
97             }
98
99            
100
101         }
  
编辑器加载中...
页: [1]
查看完整版本: vsto outlook 检查附件大小