Domino Code Fragment

Code Name*
Automate Outlook Mail From Notes
Date*
01/27/1999
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.17.128.129
Description*
Type*
LotusScript
Categories*
OLE/ActiveX Integration
Implementation:
Modify code
Required Client:
4.5
Server:
4.5
Limitations:
Users must have Lotus Notes and Outlook installed. If it fails to work check your association for an .NDL file in your registry.
Comments:
You can also send it without the user intervention by using the .Save instead of the .Display Method of the Outlook Object but that also requires you filling the Recipients filed via code as well.
Files/Graphics attachments (if applicable): Code:
What does this LotusScript do?
Mails Link Through Outlook. This action button will create a link on the fly that will be saved to the users C:Drive as link.ndl then it will call the Subroutine AutomateOutlook. This routine will display the outlook mail modal with the link embedded in the body of the mail template. The user then fills in the To: field on the modal and sends the link. The Recipients of the mail must have Lotus Notes on their machine. When they click on the link in their Outlook mail. It will then launch Notes and the link.

Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession 'Declare session as a new Notes session
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim docID As String ' Variable to hold document Universal ID
Dim ReplicaID As String ' Variable used to build Replica ID line in .NDL file
Dim HintServer As String ' Variable used to build hint server line in .NDL file
Dim ViewID As String ' Variable used to build view line in .NDL file
Dim NoteID As String ' Variable used to build document line in .NDL file

Set db = session.CurrentDatabase 'Set db to the current Notes database (open)
Set uidoc = ws.Currentdocument
Set doc = uidoc.document

' Verify that the document current exist in the database
If doc.IsNewNote Then
' Document has not been saved, warn user and exit routine
Msgbox "This document has not been saved." & Chr$(10) & Chr$(10) & "Please save prior to mailing link!", 4112, "New Document"
Exit Sub
Else
' Lets get the documents I.D.
docID = doc.UniversalID
End If

' Lets ensure that user is not attempting to send a link of a local database
If db.server = "" Then
' This is a local database and mailed link will not work, warn user and exit routine
Msgbox "You are not allowed to send a link of a local database", 4112, "Local Links Not Allowed"
Exit Sub
Else
' Build Replica line for .NDL file format = <REPLICA 8525643D:0069F618>
ReplicaID="<REPLICA " & Left$(db.ReplicaID, 8) & ":" & Right$(db.ReplicaID, 8) & ">"
End If

ViewID = ""
' Lets verify that a default view exist in this database as a view handle is need for the .NDL file
Forall x In db.Views 'Use ForAll to loop through each view in the database until the default is found
If x.IsDefaultView Then 'Test each view to see if it is the default view
' Build View line for .NDL file format = <VIEW OF0BA62705:23C5A6D0-ON8525643D:006A3AA7>
ViewID = "<VIEW OF" & Left$(x.UniversalID, 8) &":"&Mid$(x.UniversalID, 9, 8)&"-"&"ON"&Mid$(x.UniversalID, 17, 8)&":"&Right$(x.UniversalID, 8)&">"
Exit Forall 'Once the default view is found, break out of the loop
End If
End Forall

' Lets ensure that our view handle for the .NDL file was built
If ViewID = "" Then
' View handle was never built so link would give a view error, warn user and exit routine
Msgbox "This database does not contain a default view." & Chr$(10) & Chr$(10) & "Please contact your database manager!", 4112, "Default View Not Found"
Exit Sub
End If

' Build Note line for .NDL file format = <NOTE OFBCF13ED6:621BCDE2-ON852566B7:006D7E14>
NoteID = "<NOTE OF" & Left$(docID, 8) &":"&Mid$(docID, 9, 8)&"-"&"ON"&Mid$(docID, 17, 8)&":"&Right$(docID, 8)&">"
' Build Hint Server line for .NDL file format = <HINT>CN=FTLNSDEV/OU=DEV/O=FTG</HINT>
HintServer = "<HINT>"& db.server &"</HINT>"
fileNum% = Freefile()
' Assign a file name for the .NDL file that we will be mailing
fileName$ = "c:\link.ndl"

' Write out link data to C:\link.ndl
Open fileName$ For Output As fileNum%
Write #fileNum%, "<NDL>"
Write #fileNum%, ReplicaID
Write #fileNum%, HintServer
Write #fileNum%, ViewID
Write #fileNum%, NoteID
Write #fileNum%, "</NDL>"
Close fileNum%
Call AutomateOutlook()
End Sub

' This procedure automates Outlook mailing from Lotus Notes
Sub AutomateOutlook()
' 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 subject and body text.
.Subject = "Brokerage Firm Letter"
.Body = Chr$(10) & Chr$(10) & " Click the above link to launch the notes document."
' Add embedded attachment we created in the click event!
With .attachments.Add("C:\link.ndl", 1, 1, "link.ndl")
End With
'Display Mail Model to user
.Display
End With

' Close object references.
Set appOutl = Nothing
Set maiMail = Nothing
Set recMessage = Nothing
End Sub

Notes:
User must have Lotus Notes installed. Ensure that a pointer to .ndl is set to notes.exe in the machines registry.