none
Problem creating a message in Outlook 2010 from Lotus Notes application RRS feed

  • Question

  • I have an application in Lotus Notes that sends emails and my client has recently switched to Office 365.  I'm using Outlook 2010.  When I run the following code in my environment, the body does not get created, but it works if I just set mailItem.body = [string].  Unfortunately, I need to add a Notes Doc Link into it, which is supposed to be accomplished by the find / replace where I insert a notes:// link to replace the string "Link."  I suspect it might have to do with security settings in my Outlook setup.  Any help would be greatly appreciated, because I'm not sure why this isn't working in my environment but works in the client's. Also, the GetObject line doesn't work on my machine, but CreateObject apparently works for other testers in my office. 

    Here's the code (bold being the parts that interact with Outlook)

    Sub Click(Source As Button)
    Dim DB As NotesDatabase
    Dim UIDoc As NotesUIDocument
    Dim MailUIDoc As NotesUIDocument
    Dim Doc As NotesDocument
    Dim MailDoc As NotesDocument
    Dim BodyField As NotesRichTextItem
    Dim MailField As NotesRichTextItem
    Dim MailText As String
    Dim Message As String
    Dim fileNum As Integer
    Dim uniqueNow$, DocLink$
    'Dim ParentView As NotesView
    'Signature Items
    Dim PersonalSig As String
    Dim item As NotesRichTextItem

    'Variables for outlook
    Dim appOutl As Variant
    Dim myNameSpace As Variant
    Dim myOlApp As Variant
    Dim myItem As Variant
    Dim myDestFolder As Variant
    Dim myAttachments As Variant
    Dim OutlookInsp As Variant
    Dim OutlookWordDoc As Variant
    Dim OutlookWordSel As Variant
    Dim OutlookWordRange As Variant

    'Set up environment
    On Error 183 Resume Next
    On Error 208 Resume Next
    Dim Session As New NotesSession    
    Dim Workspace As New NotesUIWorkspace

    Set DB = Session.CurrentDatabase
    Set UIDoc = Workspace.CurrentDocument
    Set Doc=UIDoc.Document
    'You need an "ALL" type view ot make the NDL file work
    Dim ParentView As NotesView
    Set ParentView = DB.GetView("($All)")

    Set myOlApp = Nothing

    'Set myOlApp = GetObject(, "Outlook.Application")
    Stop
    If myOlApp Is Nothing Then 
    'Test for Outlook
    Set myOlApp = CreateObject("Outlook.Application")
    'Set myNameSpace = myOlApp.GetNameSpace("MAPI")
    End If

    'Save and refresh doc, enter date (this is separate need from creating NDL)
    Call UIDoc.Save
    Doc.DistDate=Today
    'Call UIDoc.Refresh

    If Not myOlApp Is Nothing Then 'outlook not found, put existing code in Else
    'get whomever you want to send to
    Doc.DbID=Evaluate(|@DbLookup("Notes":"NoCache";"":"";"(LinksSystem)";"ADP Directory";2;[FailSilent])|, Doc)
    Doc.EnterSendTo=Evaluate(|@Name([CN];@DbLookup("Notes":"NoCache";DbID;"(Groups2)";"Tiering Distribution";"GroupName";[FailSilent]))|, Doc)
    'set subject variable for email
    olSubject$ = "RSC Distribution: Tiering - "+Doc.Subject(0)

    'Doc Link
    Set ParentView = Db.GetView("($All)")
    DocLink$="notes:///"+Cstr(Db.ReplicaID)+"/"+Cstr(ParentView.UniversalID)+"/"+Cstr(Doc.UniversalID)

    Message="The "+Doc.Subject(0)+" has been created. RSC Representatives may respond directly.  For others, please forward your comments through your RSC Representative."+Chr(13)+Chr(13)+  "Please follow the doclink-> Link."

    'Set BodyField = Doc.GetFirstItem( "Body" )
    'Set MailField = New NotesRichTextItem( Doc, "TempBody" )

    'Call MailField.AppendText(Message)
    'Call MailField.AppendDocLink( Doc, DB.Title )
    'Call MailField.AddNewLine( 3 )
    'Call MailField.AppendRTItem( BodyField )

    'MyTestText = MailField.GetFormattedText(0,110)

    'Set MyAttachments = myItem.Attachments

    Set myItem = myOlApp.CreateItem(0) 
    myItem.Display
    myItem.To = Doc.EnterSendTo
    myItem.Subject = olSubject$
    'Insert DocLink & Body
    Set OutlookInsp = OutlookNewItem.GetInspector
    Set OutlookWordDoc = OutlookInsp.WordEditor
    Set OutlookWordSel=OutlookWordDoc.Windows(1).Selection
    OutlookWordSel.Range.InsertAfter(Message$)
    With OutlookWordSel.Find
    .Text = " Link."
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    OutlookWordSel.Find.Execute
    Set OutlookWordRange=OutlookWordSel.Range
    OutlookWordDoc.Hyperlinks.Add OutlookWordRange, DocLink$, "", "Notes Link", "Notes Link", ""
    'myItem.Body = Message

    Else  
    Msgbox ("Microsoft Outlook was not found.  Exiting.")
    Exit Sub
    End If
    End Sub


    Friday, May 17, 2013 8:51 PM