aus einer kleinen Anfrage nebenan ist inzwischen ein Projekt geworden, das ich -deutlich verallgemeinert- hier als kleines Tutorial vorstellen möchte: Wie kann man jenseits der Möglichkeiten der OL-Regeln kommende Mails anhand verschiedener Kriterien weiterverarbeiten?
Dazu hier erst einmal ein Einstiegscode (in ThisOutlookSession), der ein paar Beispielkriterien erfasst. Das Ergebnis erscheint bei jeder Mail als MsgBox, nervt also in der täglichen Arbeit massiv, also bitte nach den Tests wieder deaktivieren (oder die MsgBox-Zeile auskommentieren, das Ergebnis wird auch ins Direktfenster geschrieben).
Code: Alles auswählen
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim EntryID As Variant, mail As Outlook.mailItem, attachment As Outlook.attachment
Dim iAttachCount As Integer, iPDFCount As Integer
Dim pdfNames As String, aEntryIDs As String
aEntryIDs = Split(EntryIDCollection, ",")
For Each EntryID In aEntryIDs
Set mail = Application.Session.GetItemFromID(EntryID)
If Not mail Is Nothing Then
iAttachCount = mail.Attachments.Count
iPDFCount = 0
pdfNames = ""
For Each attachment In mail.Attachments
If InStr(attachment.FileName, ".pdf") > 0 Then
iPDFCount = iPDFCount + 1
pdfNames = pdfNames & attachment.FileName & vbCrLf
End If
Next attachment
MsgBox "Absender: " & mail.SenderName & vbCrLf & _
"Betreff: " & mail.Subject & vbCrLf & vbCrLf & _
"E-Mail-ID: " & mail.EntryID & vbCrLf & _
"Anzahl Anhänge: " & iAttachCount & vbCrLf & _
"Anzahl PDFs: " & iPDFCount & vbCrLf & _
"PDF-Dateinamen: " & vbCrLf & pdfNames
Debug.Print "Absender: " & mail.SenderName & vbCrLf & _
"Betreff: " & mail.Subject & vbCrLf & _
"E-Mail-ID: " & mail.EntryID & vbCrLf & _
"Anzahl Anhänge: " & iAttachCount & vbCrLf & _
"Anzahl PDFs: " & iPDFCount & vbCrLf & _
"PDF-Dateinamen: " & vbCrLf & pdfNames
End If
Next EntryID
End Sub
tbc
Grüße