Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To connect to Lotus Notes client/server through VB 1

Status
Not open for further replies.

cdls

Programmer
Sep 7, 2001
15
0
0
AU
Hi,
I need to connect to Lotus Notes email client through VB and embed a document in RTF/HTML format and send the mail via Lotus Notes email server.It is possible to connect to Microsoft outlook through micrsofot outlook component. Can anybody can help me out? Are there any components available through which I can connect to lotus notes email client s/w and also emebed a document in HTML or RTF format?

Thanks in advance.
 
I have the same question. Did you ever get an answer?
Robert.Weyrauch@chase.com
 
Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then
Set AttachME = MailDoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
MailDoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)
End If
'Send the document
MailDoc.PostedDate=Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
I do not understand why nobody talks about the password prompt which appears up when sending the email .


The idea of the code should be to send the mail unattended.Well this does not happen because when you run the code it prompts for the password.
I have come across many pieces of codes but all of them assume that the inbox is already open.

Does anyone has a fool proof way of sending the mails unattended from a VB program.


I have tried session.initizlise &quot;password&quot; but it does not do anything.

 
Hi all,

I need to go further then that. In my VB-application I have an object of the RitchText-type, because I need to be able to change de font en color properties of the selected text an insert screenshots as wel.

The problem with this SendNotesMail-function is that I can't pass trough a body in RTF.

Does anyone has a solution to that?

Best regards,
Tony
 
Try and use the following Class-module. It will work in conjunction with a Lotus Notes Client. (The UDT QuickMail is to quicken up the use of the class. Put it in the calling class or application.)

UDT:

Public Type QuickMail
Logon As String
OutlookPassword As String
NotesServer As String
Recipients() As String
Subject As String
Body As String
Attachment As String

End Type

E-mail class:


Option Explicit

Private moUserDB As Object
Private moNotesSession As Object
Private moMail As Object

Private mlLoggedOn As Boolean
Private mlHasDraft As Boolean
Private mlWasOpen As Boolean

'--Constants for Lotus Notes mail.
Private Const nNOTES_EMBEDDEDOBJECT = 1454
Private Const nNOTES_ATTACHMENT = 1084
Private Const sNOTES_EMBEDDEDOBJECT = &quot;Attachment&quot;

'///////////////////////////////////////////////////////////////////////////////
'////////////////////////// Public Interface ///////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////

'*******************************************************************************
'* Function : Logon (SUB)
'* Abstract : Logon to the Domino Server.
'*******************************************************************************
Public Sub Logon(Optional ByVal Login As String = vbNullString, _
Optional ByVal Password As String = vbNullString, _
Optional ByVal NotesServer As String = vbNullString)

Dim lSuccess As Boolean

On Error GoTo Err_Logon

Set moNotesSession = GetObject(vbNullString, &quot;Notes.NotesSession&quot;)

'-- If Notes was open, don't re-open it.
If Not moNotesSession.CURRENTDATABASE Is Nothing Then
Login = vbNullString
NotesServer = vbNullString

End If

'-- Open appropriate database.
Set moUserDB = moNotesSession.GETDATABASE(NotesServer, Login)

'-- Open mailbox is open, don't re-open.
If Not moUserDB Is Nothing Then
If Not moUserDB.ISOPEN Then
moUserDB.OPENMAIL

End If

lSuccess = True

Else
lSuccess = False

End If

IsLoggedOn = lSuccess

Exit_Logon:
Exit Sub

Err_Logon:
IsLoggedOn = False

GoTo Exit_Logon

End Sub

'*******************************************************************************
' Property: IsLoggedOn
'*******************************************************************************
Public Property Get IsLoggedOn() As Boolean

IsLoggedOn = mlLoggedOn

End Property

'*******************************************************************************
' Property: IsLoggedOn
'*******************************************************************************
Private Property Let IsLoggedOn(ByVal NewValue As Boolean)

mlLoggedOn = NewValue

End Property

'*******************************************************************************
' Property: HasDraft
'*******************************************************************************
Public Property Get HasDraft() As Boolean

HasDraft = mlHasDraft

End Property

'*******************************************************************************
' Property: HasDraft
'*******************************************************************************
Private Property Let HasDraft(ByVal NewValue As Boolean)

mlHasDraft = NewValue

End Property

'*******************************************************************************
'* Function : Logoff (SUB)
'* Abstract : Logoff from the Domino Server.
'*******************************************************************************
Public Sub Logoff()

With Me
If .IsLoggedOn Then
If .HasDraft Then
.DestroyDraft

End If

'-- Close inbox and database.
Call moUserDB.Close
Call moNotesSession.Close

Set moUserDB = Nothing
Set moNotesSession = Nothing

IsLoggedOn = False

End If
End With

End Sub

'*******************************************************************************
'* Function : CreateMail (FUNCTION)
'* Abstract : Create a new mail-message.
'*******************************************************************************
Public Sub CreateMail()

If Me.IsLoggedOn Then
Set moMail = moUserDB.CREATEDOCUMENT

'-- Create mail and set properties.
If Not moMail Is Nothing Then
moMail.Form = &quot;memo&quot;
moMail.SAVEMESSAGEONSEND = True

HasDraft = True

End If
End If

End Sub

'*******************************************************************************
'* Function : Send (FUNCTION)
'* Abstract : Send the created mail, and set posted date to today.
'* This wil make it appear in the send-items.
'*******************************************************************************
Public Function Send() As Boolean

On Error GoTo Err_Send

If Me.HasDraft Then
moMail.PostedDate = Now()
moMail.Send (False)

HasDraft = False

Set moMail = Nothing

End If

Send = True

Exit_Send:
Exit Function

Err_Send:
Send = False

GoTo Exit_Send

End Function

'*******************************************************************************
'* Function : DestroyDraft (SUB)
'* Abstract : Destroy all created, non-send mail.
'*******************************************************************************
Public Sub DestroyDraft()

If Me.HasDraft Then
Set moMail = Nothing

HasDraft = False

End If

End Sub

'*******************************************************************************
'* Function : AddAttachment (FUNCTION)
'* Abstract : Add an attachment to the mail-message.
'*******************************************************************************
Public Function AddAttachment(ByVal FileName As String) As Boolean

Dim oAttachment As Object
Dim oRichText As Object
Dim lSuccess As Boolean

If Me.HasDraft Then
'-- !!! Notes is Object-Oriented !!!
If FileName = vbNullString Then
lSuccess = True

Else
Set oRichText = moMail.CREATERICHTEXTITEM(sNOTES_EMBEDDEDOBJECT)
Set oAttachment = oRichText.EMBEDOBJECT(nNOTES_EMBEDDEDOBJECT, vbNullString, FileName)

lSuccess = Not oAttachment Is Nothing

Set oAttachment = Nothing
Set oRichText = Nothing

End If
Else
lSuccess = False

End If

AddAttachment = lSuccess

End Function

'*******************************************************************************
'* Function : AddSubject (FUNCTION)
'* Abstract : Add a subject to the mail-message.
'*******************************************************************************
Public Function AddSubject(ByVal Subject As String) As Boolean

Dim lSuccess As Boolean

On Error GoTo Err_AddSubject

If Me.HasDraft Then
If Subject = vbNullString Then
lSuccess = True

Else
moMail.Subject = Subject

lSuccess = True

End If
Else
lSuccess = False

End If

AddSubject = lSuccess

Exit_AddSubject:
Exit Function

Err_AddSubject:
AddSubject = False

GoTo Exit_AddSubject

End Function

'*******************************************************************************
'* Function : AddBody (FUNCTION)
'* Abstract : Add the body to the mail-message.
'*******************************************************************************
Public Function AddBody(ByVal Body As String) As Boolean

Dim lSuccess As Boolean
Dim oBody As Object

On Error GoTo Err_AddBody

If Me.HasDraft Then
If Body = vbNullString Then
lSuccess = True

Else
'-- !!! Notes is Object-Oriented !!!
Set oBody = moMail.CREATERICHTEXTITEM(&quot;Body&quot;)

Call oBody.APPENDTEXT(Body)

Set oBody = Nothing

lSuccess = True

End If
Else
lSuccess = False

End If

AddBody = lSuccess

Exit_AddBody:
Exit Function

Err_AddBody:
AddBody = False

GoTo Exit_AddBody

End Function

'*******************************************************************************
'* Function : GetAttachments (FUNCTION)
'* Abstract : Retrieve attachments from the Inbox.
'*******************************************************************************
Public Function GetAttachments(ByVal Destination As String, _
ByRef Attachments As Collection) As Boolean

Dim oAttachment As Object
Dim oMail As Object
Dim oInbox As Object
Dim oItem As Variant
Dim aValues() As String
Dim lSuccess As Boolean
Dim sFileName As String

On Error GoTo Err_GetAttachments

'-- !!! Notes is Object-Oriented !!!
If Me.IsLoggedOn Then
Set oInbox = moUserDB.GETVIEW(&quot;($Inbox)&quot;)
Set oMail = oInbox.GETFIRSTDOCUMENT

Do Until (oMail Is Nothing)
Dim colFile As New Collection

colFile.Add Trim(oMail.Subject), &quot;customer&quot;
colFile.Add Trim(oMail.Body), &quot;body&quot;

'-- Loop through all objects on the message-object.
For Each oItem In oMail.Items
If oItem.Type = nNOTES_ATTACHMENT Then

aValues = oItem.Values

Set oAttachment = oMail.GETATTACHMENT(aValues(0))

sFileName = Destination & Trim(aValues(0))

oAttachment.EXTRACTFILE (sFileName)

colFile.Add sFileName, &quot;file&quot;

End If

Attachments.Add colFile, Trim(oMail.Subject)

Set colFile = Nothing
Set oAttachment = Nothing

Next

'-- Remove current first-doc. Get new first doc.
oMail.Remove (True)
Set oMail = oInbox.GETFIRSTDOCUMENT

Loop

oInbox.Refresh

lSuccess = True

Else
lSuccess = False

End If

GetAttachments = lSuccess

Exit_GetAttachments:
Exit Function

Err_GetAttachments:
GetAttachments = False

GoTo Exit_GetAttachments

End Function

'*******************************************************************************
'* Function : AddRecipients (FUNCTION)
'* Abstract : Add recipients to the message. (Can be added as string or array)
'*******************************************************************************
Public Function AddRecipients(ByRef Recipients() As String) As Boolean

Dim lSuccess As Boolean

On Error GoTo Err_AddRecipients

If Me.HasDraft Then
moMail.SendTo = Recipients

lSuccess = True

Else
lSuccess = False

End If

AddRecipients = lSuccess

Exit_AddRecipients:
Exit Function

Err_AddRecipients:
AddRecipients = False

GoTo Exit_AddRecipients

End Function

'****************************************************************************************
'* Function : SendQuickMail (FUNCTION)
'* Abstract : Ability to send message by providing all info. through a user-defined type.
'****************************************************************************************
Public Function SendQuickMail(EMail As QuickMail) As Boolean

Dim lSuccess As Boolean

On Error GoTo Err_SendQuickMail

With Me
.Logon EMail.Logon, , EMail.NotesServer

If .IsLoggedOn Then
.CreateMail

If .HasDraft Then
.AddRecipients EMail.Recipients
.AddSubject EMail.Subject
.AddBody EMail.Body
.AddAttachment EMail.Attachment
.Send

End If

lSuccess = Not .HasDraft

End If

If lSuccess Then
.Logoff

End If
End With

SendQuickMail = lSuccess

Exit_SendQuickMail:
Exit Function

Err_SendQuickMail:
SendQuickMail = False

GoTo Exit_SendQuickMail

End Function


 
In addition to my last post: The source code provided is part of an e-mail wrapper for Notes, Outlook and Exchange. This explains the occurences of Outlook in code. If interested in Outlook-code for complete wrapper, e-mail me: ppeetoom@hotmail.com
 
For a while, I have been struggling with the fact that Notes send my e-mail without the user having the possibility of edit it.

How do I get it to pause?

In a second possibilitym can I just store the e-mail in a draft folder, waiting for the user to trigger the send function?
 
I'd like to ask Cesieac
Could you tell me, does It possible that vb connect to notes without prompting password (Or I want enter notes password via Coding)?
And Could you tell me how to close the Notes Client which are already open via your coding (Cause your coding is trying to open Notes Client first) ?


Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top