The following tutorial and code can be used to send lotus notes mail/memo using DOM in VB(Visual Basic)
This method eliminates the password prompt that will show when the notes is locked and the script is executed
Public recep, ccRecipient, passwd, savemsg, attachment1
Private Sub Form_Load()
Me.Hide
ReDim ccRecipient(4)
ReDim recep(6)
passwd="yourpasswordhere"
savemsg="yes" ' If you want the mail to be stored in your sent items, otherwise "no"
recep(0) = "rec1/company"
recep(1) = "rec2/company"
ccRecipient(0) = "rec3/company"
ccRecipient(1) = "rec4/company"
toname = "All"
attachment1 = "C:\someattachment.xls"
Call sendNotesMail(toname)
Unload Me
End Sub
Function sendNotesMail(toname)
Dim domNotesDocumentMemo As Domino.NotesDocument
Dim domSession As New Domino.NotesSession
Dim domNotesDBDir As Domino.NotesDbDirectory
Dim domNotesDatabaseMailFile As Domino.NotesDatabase
Dim DomNotesItem As Domino.NotesItem
Dim sUser As String
Dim objNotesRichTextItem As Domino.NotesRichTextItem
domSession.Initialize (passwd)
sUser = domSession.UserName
Set domNotesDBDir = domSession.GetDbDirectory(sUser)
Set domNotesDatabaseMailFile = domNotesDBDir.OpenMailDatabase
' Create a new memo document.
Set domNotesDocumentMemo = domNotesDatabaseMailFile.CreateDocument
Call domNotesDocumentMemo.AppendItemValue("Form", "Memo")
Call domNotesDocumentMemo.AppendItemValue("From", domSession.CommonUserName)
subj = "Lotus Notes Email using DOM and VB - an example"
input1 = "Hi " & toname & ","
input2 = "Lotus notes email using vb"
input3 = "Regards,"
input4 = "Your name"
mailbody = input1 & Chr(13) & input2 & Chr(13) & Chr(13) & input3 & Chr(13) & input4 & Chr(13) & Chr(13)
Call domNotesDocumentMemo.AppendItemValue("SendTo", "")
'Now get a handle on the item
Set DomNotesItem = domNotesDocumentMemo.GetFirstItem("SendTo")
'Now pass your array
For Each r In recep
If r <> "" Then
Call DomNotesItem.AppendToTextList(r)
End If
Next
'create or instantiate the item
Call domNotesDocumentMemo.AppendItemValue("CopyTo", "")
'Now get a handle on the item
Set DomNotesItem = domNotesDocumentMemo.GetFirstItem("CopyTo")
'Now pass your array
For Each s In ccRecipient
If s <> "" Then
Call DomNotesItem.AppendToTextList(s)
End If
Next
Call domNotesDocumentMemo.AppendItemValue("Subject", subj)
Set objNotesRichTextItem = domNotesDocumentMemo.CreateRichTextItem("Body")
Call objNotesRichTextItem.AppendText(mailbody)
' Call domNotesDocumentMemo.AppendItemValue("Body", mailbody)
If attachment1 <> "" Then
Call objNotesRichTextItem.EmbedObject(1454, "", attachment1, "Attachment")
End If
If Trim(LCase(savemsg)) = "yes" Then
domNotesDocumentMemo.SaveMessageOnSend = True
Else
domNotesDocumentMemo.SaveMessageOnSend = False
End If
domNotesDocumentMemo.Send (False)
Set domNotesDocumentMemo = Nothing
Set domNotesDatabaseMailFile = Nothing
Set domNotesDBDir = Nothing
Set domSession = Nothing
Set AttachME = Nothing
Exit Function
ErrorHandler:
MsgBox Err.Number & " " & Err.Description
End Function