我正在处理一个宏,该宏根据主题名称和域名检查附件名称。
目前还有一些小问题,我不希望宏将签名中的图像识别为附件。我见过的解决方案包括使用if语句来计算大小,例如只检查超过5kb的附件等。
另一个问题是,如果根本没有附件,那么宏就会崩溃!我觉得我最后需要另外一个if语句进行项目计数,但我不确定这会如何改变我在宏的末尾的条件!
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim outRecips As Outlook.Recipients
Dim outRecip As Outlook.Recipient
Dim outPropAcc As Outlook.PropertyAccessor
Dim strDomain As String
Dim lngPreDom As Long
Dim lngPostDom As Long
Dim strSubject As String
Dim objAttachments As Outlook.Attachments
Dim strAttachment As String
Dim Response As String
' set domain value
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set outRecips = Item.Recipients
For Each outRecip In outRecips
Set outPropAcc = outRecip.PropertyAccessor
strDomain = outPropAcc.GetProperty(PR_SMTP_ADDRESS)
strDomain = Split(strDomain, "@")(1)
lngPreDom = InStr(strDomain, "@")
lngPostDom = InStr(strDomain, ".")
strDomain = LCase(Mid(strDomain, lngPreDom + 1, lngPostDom - lngPreDom - 1))
Exit For
Next
' set subject value
strSubject = LCase(Item.Subject)
' set attachment name
Set objAttachments = Item.Attachments
strAttachment = LCase(objAttachments.Item(1).FileName)
' if external recipient, check email contents
If strDomain <> "exampleemail" _
Then
If InStr(strSubject, strDomain) = 0 _
Or InStr(strAttachment, strDomain) = 0 _
Or InStr(strAttachment, strSubject) = 0 _
Then
Response = "Attachment/Subject do not match Recipient(s)" & vbNewLine & "Send Anyway?"
If MsgBox(Response, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Recipients") = vbNo Then
Cancel = True
End If
End If
End If
End Sub
答案 0 :(得分:0)
使用Attachment.PropertyAccessor对象读取PR_ATTACHMENT_HIDDEN属性(http://schemas.microsoft.com/mapi/proptag/0x7FFE000B);如果它是真的它是一个嵌入的图像(通常在签名中)。