Mit den folgenden Klassen ist es möglich, aus einer Domäne heraus, eine beliebige Lotus Notes-Datenbank zu öffnen und alle E-Mails darin aufzulisten. Es werden dabei alle Dateianhänge aus den E-Mails in eine Liste gefügt.
Wie man E-Mails über einen Lotus Domino Server versendet, habe ich hier beschrieben.
Ein Beispielaufruf findet sich am Ende dieses Artikels.
Public Class NotesMail Public Subject As String Public From As String Public Body As String Public AttachmentFilenames As New List(Of Domino.NotesEmbeddedObject) End Class Public Class NotesMailCollection Inherits List(Of NotesMail) End Class Public Class MailAccount Public Host As String Public DatabaseFilename As String Public Password As String End Class Public Class NotesTools Public Shared Function GetMails(ByVal aMailAccount As MailAccount, ByVal MoveMails As Boolean) As NotesMailCollection Try Return _GetMails(aMailAccount, MoveMails) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) Return Nothing End Try End Function Private Shared Function _GetMails(ByVal aMailAccount As MailAccount, ByVal MoveMails As Boolean) As NotesMailCollection ' Die Session starten Dim Session As New Domino.NotesSession Session.Initialize(aMailAccount.Password) ' Datenbank öffnen Dim MailDB As Domino.NotesDatabase Dim MailServer As String = Session.GetEnvironmentString("MailServer", True) ' Dim DatabaseFilename As String = Session.GetEnvironmentString("MailFile", True) MailDB = Session.GetDatabase(MailServer, aMailAccount.DatabaseFilename) If Not MailDB.IsOpen Then MailDB.Open() End If Dim result As New NotesMailCollection Dim n_View As Domino.NotesView Dim n_ViewNav As Domino.NotesViewNavigator Dim n_ViewEntry As Domino.NotesViewEntry Dim n_Document As Domino.NotesDocument n_View = MailDB.GetView("($Inbox)") n_ViewNav = n_View.CreateViewNav n_ViewEntry = n_ViewNav.GetFirstDocument ' For all mails Do While Not (n_ViewEntry Is Nothing) n_Document = n_ViewEntry.Document Dim oAttachment As Domino.NotesEmbeddedObject If n_Document.HasEmbedded Then ' Add data to our object Dim nm As New NotesMail With nm .Body = n_Document.GetItemValue("Body")(0).ToString .Subject = n_Document.GetItemValue("Subject")(0).ToString .From = n_Document.GetItemValue("From")(0).ToString End With Dim fileNames As Object() = Session.Evaluate("@AttachmentNames", n_Document) For Each fileName As String In fileNames oAttachment = n_Document.GetAttachment(fileName) nm.AttachmentFilenames.Add(oAttachment) Next ' Add object to our list result.Add(nm) ' Remove from list If MoveMails Then ' n_Document.PutInFolder("Importiert " & Now.ToShortDateString, True) ' n_Document.RemoveFromFolder("($Inbox)") End If End If ' Next Mail n_ViewEntry = n_ViewNav.GetNextDocument(n_ViewEntry) Loop Return result End Function End Class
public Sub Test ' Account Einstellungen Dim acc As New MailAccount With acc .Host = "DominoServer" .DatabaseFilename = "mail\postfach.nsf" .Password = "meingeheimespasswort" End With ' GO! GO! GO! Alle Mails auflisten Dim lstMails As NotesMailCollection = NotesTools.GetMails(acc, False) For Each itm As NotesMail In lstMails ' Alle Anhänge in Verzeichnis abspeichern For Each att As Domino.NotesEmbeddedObject In itm.AttachmentFilenames strFilename = att.Name strDirectory = "C:\tmp" My.Computer.FileSystem.CreateDirectory(strDirectory) strFullFilename = strDirectory & "\" & strFilename att.ExtractFile(strFullFilename) Next Next end sub
0 Antworten zu VB .NET - Mit Lotus Notes E-Mails und Dateianhängen arbeiten