我有这个代码在传入的消息上运行。它剥离附件然后将电子邮件转发到不同的地址。它被读取收据打破,因为我猜它们不算作MailItem。
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryID As Variant
For Each varEntryID In Split(EntryIDCollection, ",")
Dim objOriginalItem As MailItem
Set objOriginalItem = Application.GetNamespace("MAPI").GetItemFromID(varEntryID)
Dim objForwardedItem As MailItem
Set objForwardedItem = objOriginalItem.Forward
Do Until objForwardedItem.Attachments.Count = 0
objForwardedItem.Attachments.Remove (1)
Loop
objForwardedItem.DeleteAfterSubmit = True
objForwardedItem.To = "LoanPostClosing@domain.com"
objForwardedItem.Send
Next
End Sub
答案 0 :(得分:1)
您需要将新项目视为通用对象并检查Class属性。见下文。
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryID As Variant
For Each varEntryID In Split(EntryIDCollection, ",")
Dim objOriginalItem As Object
Set objOriginalItem = Application.GetNamespace("MAPI").GetItemFromID(varEntryID)
if objOriginalItem.Class = 43 Then
Dim objForwardedItem As MailItem
Set objForwardedItem = objOriginalItem.Forward
Do Until objForwardedItem.Attachments.Count = 0
objForwardedItem.Attachments.Remove (1)
Loop
objForwardedItem.DeleteAfterSubmit = True
objForwardedItem.To = "LoanPostClosing@yourcnb.com"
objForwardedItem.Send
End If
Next
End Sub