我们正在建设一个VSTO Outlook加载项,扫描传出邮件的附件提醒用户,发现一些意想不到的行为。
考虑将文件添加到Outlook邮件的方法如下:
所有四个公认的附件时,该项目发送事件触发:
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
在下面的代码例如:
For Each attachment As Outlook.Attachment In Item.Attachments
'do some stuff like check attachment size
Next
我们正在检查在签名文件小的嵌入式的图像,不想通知用户。
在下列情况下:
我们注意到,当添加的文件被嵌入图像(不是附件),我们没有看到正确的尺寸属性使用图像:
attachment.Size
IE:假设我们正在发送一个具有Outlook电子邮件:
我们的代码似乎认识到附件的正确数目,但是如果我们检查的屏幕截图或签名档图片,附件大小属性始终计算结果为0,我们认为,附件大小是由于该文件不存在对磁盘和附加文件一样。
For Each attachment As Outlook.Attachment In Item.Attachments
if attachment.size > 755 then
'ignore the image
end if
Next
有没有一种方法来检查在VB.Net图像尺寸还是我们需要关闭文件保存到一个临时目录,以做到这一点?
编辑展望间谍故障排除步骤:
我怀疑,步骤4和7之间的差异可能是由于这样的事实,Outlook可能保存电子邮件草稿?
附加编辑
代码添加检查签名/嵌入式图像尺寸之前保存邮件:
'convert generic object to Outlook.MailItem object.
Dim objMailItem As Outlook.MailItem = CType(Item, Outlook.MailItem)
'Save message
objMailItem.Save()
'quick check to see if message is saved (it is)
Dim saved As Boolean = objMailItem.Saved()
For Each attachment As Outlook.Attachment In objMailItem.Attachments
'all items still evaluate to 0.
If attachment.Size >= 20 Then
'do some stuff
End If
Next
谢谢。
附件大小(包括原始二进制数据以及所述每附件属性)由存储提供当mesage保存更新。请务必先打电话MailItem.Save
。
我们结束了使用Outlook间谍(真棒工具..)找到PR_ATTACH_SIZE属性:
然后设置使用MS的模式如下:
'property access to get attachment sizes
Const PR_ATTACH_SIZE As String = "http://schemas.microsoft.com/mapi/proptag/0x0E200003"
此外,从this SO邮政伟大的信息。
然后通过我们的附件集合迭代如下找到我们的附件大小:
For Each attachment As Outlook.Attachment In Item.Attachments
attSize = CType(attachment.PropertyAccessor.GetProperty(PR_ATTACH_SIZE), Integer)
if attSize.size > 755 then
'ignore the image
end if
Next
谢谢..