Lotus Notes emails

adaniele

Registered User.
Local time
Tomorrow, 02:10
Joined
Jul 18, 2005
Messages
176
Hi guys, here is my problem.

I am sending emails when the user press a button, but the problem is:

1 - How to check is LNotes is open
2- How to know if the user needs to enter the password.

With the following code an email is sent ONLY if notes is open AND the psw is not required.

Code:
Public Sub Sendmailf(Task As String)

    Dim nSession As Object
    Dim CurrentUser As String
    Dim DataBaseName As String
    Dim nDatabase As Object
    Dim nMailDoc As Object
    Dim nSendTo(60) As String    'array for 60 e-mail address
    Dim EmbeddedObj As Object

    Set nSession = CreateObject("Notes.NotesSession")
    CurrentUser = nSession.username
    DataBaseName = Left$(CurrentUser, 1) & Right$(CurrentUser, _
         (Len(CurrentUser) - InStr(1, CurrentUser, " "))) & ".nsf"
    Set nDatabase = nSession.GETDATABASE("", DataBaseName)
    Call nDatabase.OPENMAIL
    Set nMailDoc = nDatabase.CREATEDOCUMENT
    With nMailDoc
          
             nSendTo(0) = vemail
             .Form = "Memo"
             .Body = Chr(13) & Chr(13) & Chr(13) & Chr(13) & _
                     "Status: " & Me.status & Chr(13) & _
                     "Creation Date: " & Me.Open_dt & Chr(13) & _
                     "Effective Date: " & Me.effective_dt & Chr(13) & _
                     "Completion Date: " & Me.completion_dt & Chr(13) & _
                     "Requester: " & vreq & Chr(13) & _
                     "Actioned By: " & Me.Assignee & Chr(13) & _
                     "Description: " & Chr(13) & Me.description & Chr(13) & _
                     Chr(13) & Chr(13) & Chr(13) & Chr(13) & _
                     Chr(13) & Chr(13) & Chr(13) & Chr(13) & _
                     "Validation Signature: ................................." & vreq
                     
             .sendto = nSendTo
             .Subject = "Task: " & Task_Num & " is Ready to be Validated"
             .Importance = "0"
             .SEND (False)
    End With

    Set nDatabase = Nothing
    Set nMailDoc = Nothing
    Set nSession = Nothing
    Set EmbeddedObj = Nothing
End Sub

thx for your help
 
Guys, i found a few answers in the forum and it is working. However, i'd like to know if there is any chance to force Lotus Notes to ask the password when the DB is locked.

any suggestion?

Code:
Public Sub Sendmail(Task As String)

    Dim nSession As Object
    Dim CurrentUser As String
    Dim DataBaseName As String
    Dim nDatabase As Object
    Dim nMailDoc As Object
    Dim nSendTo(60) As String    'array for 60 e-mail address
    Dim EmbeddedObj As Object

    Set nSession = CreateObject("Notes.NotesSession")
    CurrentUser = nSession.username
    DataBaseName = Left$(CurrentUser, 1) & Right$(CurrentUser, _
         (Len(CurrentUser) - InStr(1, CurrentUser, " "))) & ".nsf"
    Set nDatabase = nSession.GETDATABASE("", DataBaseName)
    Call nDatabase.OPENMAIL
    
    On Error GoTo ErrorLogon
    ' See if user is logged on yet;
    ' if not, the error handler will kick in!
    Set nMailDoc = nDatabase.CreateDocument
    On Error GoTo 0
    
    'Set nMailDoc = nDatabase.CreateDocument
    With nMailDoc
          
             nSendTo(0) = "M@a"
             .Form = "Memo"
             .Body = Chr(13) & Chr(13) & Chr(13) & Chr(13) & _
                     " Previous description: " & vdescription & Chr(13) & Chr(13) & _
                     " New description: " & Me.description
             .sendto = nSendTo
             .Subject = "Task: " & Task_Num & " has been modified"
             .Importance = "0"
             .SEND (False)
    End With

    Set nDatabase = Nothing
    Set nMailDoc = Nothing
    Set nSession = Nothing
    Set EmbeddedObj = Nothing
    
ErrorLogon:
    If Err.Number = 7063 Then
        MsgBox "Please login to Lotus Notes first and then click the 'SAVE' button.", vbCritical
        Set nDatabase = Nothing
        Set nMailDoc = Nothing
        Set nSession = Nothing
        Set EmbeddedObj = Nothing
        Exit Sub
    End If
End Sub
 
Searching thru this form, I’m having the same problem, did you ever find a solution?
 
i did not find a solution. with my current code the user cannot close the form until the user is logged into LN.
 
This might help. I found this code last year posted in the Code Repository by KeithIT (you are a lifesaver, Keith!). Check out the "CreateNotesSession" function. I made a slight chance in the original code to the "CreateNotesSession" function to first check to see if Notes is open (originally it opened always and then checked to see if the user wanted to edit within Notes), if not, it opens a session and the password Window pops to the foreground.

Code:
Code:
'***Code originated at http://www.access-programmers.co.uk/forums
'***in the Code Repository Forum by KeithIT


' ##################################################  ###################################

' Tested to work with Windows NT 4 and higher NT-Versions (2000 / XP / 2003)
' Tested with Lotus Client 5.07 and higher

' The Lotus client has to be installed
' If a password, different form the NT one is choosen, Lotus has to be open
' in beforehand before this script can be used.

' ##################################################  ###################################

Const EMBED_ATTACHMENT As Integer = 1454
Const EMBED_OBJECT As Integer = 1453
Const EMBED_OBJECTLINK As Integer = 1452


Declare Function SetForegroundWindow Lib "user32" (ByVal Hwnd As Long) As Long
Declare Function ShowWindow& Lib "user32" (ByVal Hwnd As Long, ByVal nCmdShow As Long)

Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Function CreateNotesSession&(Optional edit As Boolean = True)
On Error GoTo HandleErr

Const notesclass$ = "NOTES"
' "Neues Memo - Lotus Notes"
Const SW_SHOWMAXIMIZED = 3
Dim Lotus_Session As Object

Dim rc&
Dim lotusWindow&
'Set Lotus_Session = CreateObject("Notes.NotesSession")

DoEvents
DoEvents
lotusWindow = FindWindow(notesclass, vbNullString)

If lotusWindow <> 0 Then
    If edit = True Then
        rc = ShowWindow(lotusWindow, SW_SHOWMAXIMIZED)
        rc = SetForegroundWindow(lotusWindow)
        CreateNotesSession& = True
    Else
        CreateNotesSession& = True
    End If
Else
    CreateNotesSession& = False
    Set Lotus_Session = CreateObject("Notes.NotesSession")
    lotusWindow = FindWindow(notesclass, vbNullString)
    rc = SetForegroundWindow(lotusWindow)
 End If

ExitHere:
    Exit Function
    
HandleErr:
    If Err.Number = "8965" Then
        Resume ExitHere
    Else
        MsgBox "Error #" & Err.Number & ": " & Err.Description & " at " & Err.Source
        Resume ExitHere
    End If
    
End Function

Sub CreateMailandAttachFile(Optional IsSubject As String = "", Optional ByRef SendToAdr As Variant, Optional CCToAdr As Variant, Optional BCCToAdr As Variant = "", Optional IsBody As String, Optional Attach1 As String = "", Optional Attach2 As String = "", Optional MailDB As String = "", Optional edit As Boolean = True, Optional Servr As String = "", Optional Acct As String = "")

Dim s As Object ' use back end classes to obtain mail database name
Dim db As Object '
Dim doc As Object ' front end document
Dim beDoc As Object ' back end document
Dim workspace As Object ' use front end classes to display to user
Dim bodypart As Object '

Call CreateNotesSession(False)

Set s = CreateObject("Notes.Notessession") 'create notes session
Set db = s.GetDatabase(Servr, Acct) 'set db to server and file name, if not supplied via code will automatically use the default mail db
     If db.IsOpen = True Then
        Else
            Call db.OPENMAIL 'open db to send mail
     End If
Set beDoc = db.CreateDocument
Set bodypart = beDoc.CreateRichTextItem("Body")


' Filling the fields
'###################
beDoc.Subject = IsSubject  'Subject line
beDoc.Body = IsBody  'Mail message
beDoc.SendTo = SendToAdr  'To:
beDoc.CopyTo = CCToAdr  'CC:
beDoc.BlindCopyTo = BCCToAdr  'Bcc:
'beDoc.From = IsFrom  'Sending email address, must be a valid notes account
   'name
'beDoc.PRINCIPAL = IsPrincipal  'Sender's name.  May be anything (literally).
   'Will show in the "From" field in most email agents
beDoc.SaveOnSend = True  'tells notes to put message in sent folder

'''''''''''''''''''''''''
''For multiple email addresses you just set beDoc.sendto (or CopyTo or
''BlindCopyTo) to an array of variants each of which will receive the message. So:

'Dim recip() as variant
'z = item count
'Redim recip(z)
'y = 0
'For i = 0 to ctrl.itemcount
'   recip(y) = "emailaddress1"
'   y = y + 1
'next i

'beDoc.sendto = recip
''''''''''''''''''''''''

' Attaches I
'###########
' Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", DirWithPathFileName, FileName)
If Len(Attach1) > 0 Then
    If Len(Dir(Attach1)) > 0 Then
        Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, Dir(Attach1))
    End If
End If

' Attaches II
'############
If Len(Attach2) > 0 Then
    If Len(Dir(Attach2)) > 0 Then
        Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach2, Dir(Attach2))
    End If
End If

If edit = True Then
    Set workspace = CreateObject("Notes.NotesUIWorkspace")
      'Position cursor in body of email
    Call workspace.EDITDOCUMENT(True, beDoc).GOTOFIELD("Body")
Else
    beDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder with current date and time
    beDoc.Save True, True    'Saves to Sent Folder
    beDoc.Send 0, SendToAdr

End If

Set s = Nothing

End Sub
 
Code:
'***Code originated at 
           '***in the Code Repository Forum by KeithIT


' ##################################################  ###################################

' Tested to work with Windows NT 4 and higher NT-Versions (2000 / XP / 2003)
' Tested with Lotus Client 5.07 and higher

' The Lotus client has to be installed
' If a password, different form the NT one is choosen, Lotus has to be open
' in beforehand before this script can be used.

' ##################################################  ###################################

Const EMBED_ATTACHMENT As Integer = 1454
Const EMBED_OBJECT As Integer = 1453
Const EMBED_OBJECTLINK As Integer = 1452


Declare Function SetForegroundWindow Lib "user32" (ByVal Hwnd As Long) As Long
Declare Function ShowWindow& Lib "user32" (ByVal Hwnd As Long, ByVal nCmdShow As Long)

Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Function CreateNotesSession&(Optional edit As Boolean = True)
On Error GoTo HandleErr

Const notesclass$ = "NOTES"
' "Neues Memo - Lotus Notes"
Const SW_SHOWMAXIMIZED = 3
Dim Lotus_Session As Object

Dim rc&
Dim lotusWindow&
'Set Lotus_Session = CreateObject("Notes.NotesSession")

DoEvents
DoEvents
lotusWindow = FindWindow(notesclass, vbNullString)

If lotusWindow <> 0 Then
    If edit = True Then
        rc = ShowWindow(lotusWindow, SW_SHOWMAXIMIZED)
        rc = SetForegroundWindow(lotusWindow)
        CreateNotesSession& = True
    Else
        CreateNotesSession& = True
    End If
Else
    CreateNotesSession& = False
    Set Lotus_Session = CreateObject("Notes.NotesSession")
    lotusWindow = FindWindow(notesclass, vbNullString)
    rc = SetForegroundWindow(lotusWindow)
 End If

ExitHere:
    Exit Function
    
HandleErr:
    If Err.Number = "8965" Then
        Resume ExitHere
    Else
        MsgBox "Error #" & Err.Number & ": " & Err.Description & " at " & Err.Source
        Resume ExitHere
    End If
    
End Function

Sub CreateMailandAttachFile(Optional IsSubject As String = "", Optional ByRef SendToAdr As Variant, Optional CCToAdr As Variant, Optional BCCToAdr As Variant = "", Optional IsBody As String, Optional Attach1 As String = "", Optional Attach2 As String = "", Optional MailDB As String = "", Optional edit As Boolean = True, Optional Servr As String = "", Optional Acct As String = "")

Dim s As Object ' use back end classes to obtain mail database name
Dim db As Object '
Dim doc As Object ' front end document
Dim beDoc As Object ' back end document
Dim workspace As Object ' use front end classes to display to user
Dim bodypart As Object '

Call CreateNotesSession(False)

Set s = CreateObject("Notes.Notessession") 'create notes session
Set db = s.GetDatabase(Servr, Acct) 'set db to server and file name, if not supplied via code will automatically use the default mail db
     If db.IsOpen = True Then
        Else
            Call db.OPENMAIL 'open db to send mail
     End If
Set beDoc = db.CreateDocument
Set bodypart = beDoc.CreateRichTextItem("Body")


' Filling the fields
'###################
beDoc.Subject = IsSubject  'Subject line
beDoc.Body = IsBody  'Mail message
beDoc.SendTo = SendToAdr  'To:
beDoc.CopyTo = CCToAdr  'CC:
beDoc.BlindCopyTo = BCCToAdr  'Bcc:
'beDoc.From = IsFrom  'Sending email address, must be a valid notes account
   'name
'beDoc.PRINCIPAL = IsPrincipal  'Sender's name.  May be anything (literally).
   'Will show in the "From" field in most email agents
beDoc.SaveOnSend = True  'tells notes to put message in sent folder

'''''''''''''''''''''''''
''For multiple email addresses you just set beDoc.sendto (or CopyTo or
''BlindCopyTo) to an array of variants each of which will receive the message. So:

'Dim recip() as variant
'z = item count
'Redim recip(z)
'y = 0
'For i = 0 to ctrl.itemcount
'   recip(y) = "emailaddress1"
'   y = y + 1
'next i

'beDoc.sendto = recip
''''''''''''''''''''''''

' Attaches I
'###########
' Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", DirWithPathFileName, FileName)
If Len(Attach1) > 0 Then
    If Len(Dir(Attach1)) > 0 Then
        Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, Dir(Attach1))
    End If
End If

' Attaches II
'############
If Len(Attach2) > 0 Then
    If Len(Dir(Attach2)) > 0 Then
        Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach2, Dir(Attach2))
    End If
End If

If edit = True Then
    Set workspace = CreateObject("Notes.NotesUIWorkspace")
      'Position cursor in body of email
    Call workspace.EDITDOCUMENT(True, beDoc).GOTOFIELD("Body")
Else
    beDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder with current date and time
    beDoc.Save True, True    'Saves to Sent Folder
    beDoc.Send 0, SendToAdr

End If

Set s = Nothing

End Sub

Hello everyone. I am new here. I have a problem with Lotus e-mail and this code. My company changed mail programm. We are using Outlook now. When we used Lotus, integrated to excel VBA macros.And now, i integrated to Outlook other moduls. But i can't make this code. I need this code counterpart for Outlook.

Please help me.
 

Users who are viewing this thread

Back
Top Bottom