I’m trying to send an email through a VB app using Lotus Notes. I’ve read several other posts (thanks for that note about registering the DLL…), found some examples but am still having a problem specifying the actual message information (From, To, Subject, etc…). Here’s some sample code that I’ve been working with:
Dim s As New NotesSession
Dim db As New NotesDatabase
Dim doc As New NotesDocument
Call s.InitializeUsingNotesUserName(“scanner”)
Set db = s.GETDATABASE("ASC_N1", "mail\scanner.nsf")
Set doc = db.CreateDocument
doc.Form = "Memo"
doc.Subject = "My Subject"
doc.Body = "Your text goes here"
’ Call doc.Send(False)
When this hits the line of code that says “DOC.FORM = ‘MEMO’” I get an error “Object does not support this property or method”. I’ve created a reference in my VB project to the “Lotus Domino Objects” (domobj.tlb), but when I look in the VB object browser there is no method or property called “Form” under the NotesDocument class. Nor is there a method or property for Subject, Body, etc…
Any assistance would be greatly appreciated…
Thanks.
Subject: Sending an Email in VB with Lotus
To set fields through COM, use the full syntax:
doc.ReplaceItemValue(“Form”,“Memo”)
doc.ReplaceItemValue(“Subject”,“My Subject”)
You may also want to consider using the NotesRichTextItem methods on the body field.
Subject: Sending an Email in VB with Lotus
Try this code :
Private Sub Form_Load()
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)
'If Time = “12:00:00” Then
'Start a session to notes
Set session = CreateObject("Notes.NotesSession")
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
With MailDoc
.Form = "Memo"
.SendTo = "xy@domain.co"
.Subject = "test"
.Body = "Hello World"
.SAVEMESSAGEONSEND = False 'SaveIt
.CREATERICHTEXTITEM ("H:\data\tmp\events.xls")
'Send the document
.PostedDate = Now() 'Gets the mail to appear in the sent items folder
.SEND False
End With
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
Rem Attachment = "H:\data\tmp\events.xls"
Rem If Attachment <> "" Then
Rem Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Rem Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
Rem MailDoc.CREATERICHTEXTITEM ("Attachment")
Rem End If
'Level.Caption = Str(Val(Level.Caption) + 1)
End Sub