Domino Code Fragment

Code Name*
Automated Outlook Mail agent!
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.131.110.169
Description*
This agent takes the e-mail field from selected documents and displays the MS Outlook mail template with the To: Field populated with those addresses.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

1. Create a shared agent called e-mail.

2. Set it to run manually from the agents list and to act on selected documents.

3. Create and action button in you view that calls the "(E-mail)" agent.

4. Change the REmail in the following code to the name of the field that you are using
   retain the e-mail address.

Sub Initialize
    Dim session As New NotesSession  'Declare session as a new Notes session
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim recMessage As Variant ' Variable for mail Recipients
    Dim collection As NotesDocumentCollection
    Dim item As NotesItem
   
    Set db = session.CurrentDatabase
    Set collection = db.UnprocessedDocuments
    For i = 1 To collection.Count
         Set doc = collection.GetNthDocument( i )
         Set item = doc.GetFirstItem( "REmail" )
         If item.values(0) <> "NA" Then
              If item.values(0) <> "" Then
                   If recMessage = "" Then
                        recMessage = item.values(0)
                   Else
                        recMessage = recMessage + "; " + item.values(0)
                   End If
              End If
         End If
    Next i
    Call AutomateOutlook(recMessage)
End Sub



' This procedure automates Outlook mailing from Lotus Notes
Sub AutomateOutlook(recMessage As Variant)
    ' Set our Outlook object
    Set appOutl = CreateObject("Outlook.Application")
    ' Get the MAPI Namespace
    Set myNameSpace = appOutl.GetNameSpace("MAPI")
    ' Variable to Outlook MailItem
    Dim maiMail As Variant
    ' Set a reference to the MailItem object.
    Set maiMail = appOutl.CreateItem(olMailItem)
   
    With maiMail
         ' Add e-mail Address from contatc documents.
         Set recMessage = .Recipients.Add(recMessage)
        ' Add subject and body text.
         .Subject = "Sicav Tracker"
         '.Body = Chr$(10) & Chr$(10) & "    Click the above link to launch the notes document."      
         'Display Mail Model to user
         .Display
    End With
   
   ' Close object references.
    Set appOutl = Nothing
    Set maiMail = Nothing
    Set recMessage = Nothing
End Sub