This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal


Oct 21, 2015, 4:38 PM
1 Posts

VBA to send mail from Excel - crashes Notes 9

  • Category: Notes Client
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer,End User
  • Tags:
  • Replies: 2

We have some code cobbled together to send email from Excel, through the Notes client. This was working on 8.5, but now causes Notes 9 to either hang or crash. The behaviour is perplexing, as this code works when the strAttach argument is passed in one case, but doesn't in another. Any assistance would be greatly appreciated!

Sub SendWithLotus(Optional strsubject, Optional strmsg, Optional strto, Optional strAttach, Optional strBlindCC)
Dim noSession As Object, noDatabase As Object, noDocument As Object, uiDocument As Object
Dim obAttachment As Object, EmbedObject As Object
Dim stSubject As Variant
Dim vaRecipient As Variant, vaMsg As Variant
Dim strProfileEnableSignature As String, BaseDir As String, strLen As Long
Dim DavArr As Variant
Const EMBED_ATTACHMENT As Long = 1454

On Error Resume Next
'BaseDir = "\\redacted\"
'Otherdir = "redacted\"

Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument

If Not IsMissing(strAttach) Then
BaseDir = strAttach
    If Left(strAttach, 5) = "https" Then
         strLen = Len(strAttach)
         DavDir = Replace(strAttach, "/", "\")
         DavArr = Split(DavDir, "\")
         BaseDir = "\\" & DavArr(2) & "@SSL\DavWWWRoot\" & Right(DavDir, strLen - 34)
        
    End If
    
    Set obAttachment = noDocument.CreateRichTextItem("Attachment1")
    Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", BaseDir)

End If

'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = strto
.Subject = strsubject
'.Body = strmsg     'Removed so that the body can be added before the signature
.BlindCopyTo = strBlindCC
.SaveMessageOnSend = True
End With

'Create the e-mail document
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EDITDOCUMENT(True, noDocument)

'Insert the body text before the signature
Set uiDocument = workspace.CURRENTDOCUMENT
Call uiDocument.GOTOFIELD("Body")
Call uiDocument.INSERTTEXT(strmsg & vbCrLf)

'Release objects from the memory.
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
Set uiDocument = Nothing

WriteLog (strsubject)
MsgBox "The e-mail has been created - please switch to your Notes client to send.", vbInformation
End Sub

 

Oct 22, 2015, 11:04 AM
100 Posts
More about StrAttach

You say that the code works, then doesn't work, when strAttach is passed in.

Can you be more specific? What exactly is being passed in? Is there a pattern associated with crash vs not crash? Is the thing at the location actually there and does that have anything to do with the crash? What is the VBA debugger telling you? It looks like you may be trying to attach a file at an http(s) address, are you sure that works? (I haven't tried it so I have no clue if it's possible, just asking the question).

 

Oct 30, 2015, 5:15 PM
12 Posts
Front end classes are not supported via com
the code being used here is using front end classes and those front end classes are only supported in the actual Notes client and not when we are using COM objects and that is what we are using here.  I'm surprised this worked for you at all in the 8.5 code stream.

The following should be rewritten to not use the front end classes

Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EDITDOCUMENT(True, noDocument)

'Insert the body text before the signature
Set uiDocument = workspace.CURRENTDOCUMENT
Call uiDocument.GOTOFIELD("Body")
Call uiDocument.INSERTTEXT(strmsg & vbCrLf)

Also the command OpenMail is only valid using COM either,  we need to use OpenMailDatabase for COM.

Something like the following can be used.  It will not use the add the signature as the comments were indicating but the signature can be appending to the body field using the NotesRichttextItem append signature as well.

Sub SendWithLotus(Optional strsubject, Optional strmsg, Optional strto, Optional strAttach, Optional strBlindCC)
Dim noSession As Object, noDatabase As Object, noDocument As Object, uiDocument As Object
Dim obAttachment As Object, EmbedObject As Object
Dim stSubject As Variant
Dim vaRecipient As Variant, vaMsg As Variant
Dim strProfileEnableSignature As String, BaseDir As String, strLen As Long
Dim DavArr As Variant
Const EMBED_ATTACHMENT As Long = 1454
On Error Resume Next
'BaseDir = "\\redacted\"
'Otherdir = "redacted\"
Set noSession = CreateObject("Notes.NotesSession")
set dir = noSession.GetDbDirectory
set noDatabase = dir.OpenMailDatabase

'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument
Set obAttachment = noDocument.CreateRichTextItem("Body")
If Not IsMissing(strAttach) Then
BaseDir = strAttach
    If Left(strAttach, 5) = "https" Then
         strLen = Len(strAttach)
         DavDir = Replace(strAttach, "/", "\")
         DavArr = Split(DavDir, "\")
         BaseDir = "\\" & DavArr(2) & "@SSL\DavWWWRoot\" & Right(DavDir, strLen - 34)
       
    End If
   

    Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", BaseDir)
End If
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = strto
.Subject = strsubject
'.Body = strmsg     'Removed so that the body can be added before the signature
.BlindCopyTo = strBlindCC
.SaveMessageOnSend = True
End With
call obattachment.AppendText(strmsg & vbCrLF)
Call noDocument.Send(False)

'Release objects from the memory.
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
Set uiDocument = Nothing
WriteLog (strsubject)
MsgBox "The e-mail has been created - please switch to your Notes client to send.", vbInformation
End Sub
 


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal