SendObject to Lotus Notes failing

SendObject to Lotus Notes failing

am 22.11.2007 17:32:40 von Roy Tong

I'm using SendObject to generate an email to a list that I have built
up in a string variable from email addresses held in a text field
within a table. The string of email addresses looks OK. I know this
because I've msgboxed it. However while it works OK for the first two
email addresses when I try three or more although it seems to work OK
within Access, the list is corrupt in the generated LN email.

My experience with Access VB is only rudimentary but I think the
following code is OK:

Private Sub SendMail_Click()
On Error GoTo ErrorSendMail_Click
Dim wsp As Workspace
Dim rSetMail As Recordset
Dim qdf As QueryDef
Dim MailList As String
Set wsp = DBEngine.Workspaces(0) ' Allocate workspace for
database
Set qdf = CurrentDb.QueryDefs("qryContactEmail")
For Each prm In qdf.Parameters 'ensure parameters are
evaluated correctly so query name is recognised
prm.Value = Eval(prm.Name)
Next prm

Set rSetMail = qdf.OpenRecordset(dbOpenDynaset)
If rSetMail.RecordCount = 0 Then GoTo NobodytoEmail
MailList = ""
rSetMail.MoveFirst
Do While Not rSetMail.EOF
MailList = MailList & rSetMail![ContactName] & ";"
MsgBox MailList
rSetMail.MoveNext ' move to next record
Loop

DoCmd.SendObject , , acFormatRTF, MailList
Exit Sub

NobodytoEmail:
MsgBox "No contacts have been selected"

ExitSendMail_Click:
Exit Sub

ErrorSendMail_Click:
MsgBox "Error " & Err.Number & ":" & Err.Description
Resume ExitSendMail_Click
End Sub

Anyway I reckon this is a failure within Lotus Notes. Does anyone know
of such a problem or have I just done something wrong in my code?

Thanks,

Roy

Re: SendObject to Lotus Notes failing

am 23.11.2007 10:53:45 von The Frog

Hi Roy,

I remember this lovely issue :-) Attempting to send information
through Lotus Notes like this really is like beating your head against
a wall. The easier way around the problem is to work with the lotus
object model and create the email that way.

If you go digging on the Lotus (IBM) website you can find a lot of
free material on the Domino Object Model, and in particular one
fantastic book (now freely downloadable as a pdf if I am not mistaken)
called "COM Together with Domino" (item # SG24-5670-00). This has
almost everything you will need to be able to play with Lotus through
VB / VBA and is well worth the effort to get from the website.

In the meantime I have some sample code for you to eyeball that you
could modify to work for your needs:

1/ Make a reference to the Lotus Domino Objects under tools ->
references

Function SendNotesMail(password As String, subject As String, bodytext
As String, Target As String, Optional attachment As String) As Boolean

On Error GoTo errorhandler

Dim Session As New NotesSession
Dim MailDB As NotesDatabase
Dim MailDoc As NotesDocument
Dim objAttachment As Object

Call Session.Initialize(password)

Set notesdir = Session.GetDbDirectory("")
Set MailDB = notesdir.OpenMailDatabase

If MailDB.IsOpen = False Then
MailDB.openmail
End If

Set MailDoc = MailDB.CreateDocument

Call MailDoc.ReplaceItemValue("Form", "Memo")
Call MailDoc.ReplaceItemValue("Subject", subject)
'Call MailDoc.ReplaceItemValue("Body", bodytext) ' this also works for
just plain text with no attachments
Call MailDoc.ReplaceItemValue("PostedDate", Now())

Set emailbody = MailDoc.CreateRichTextItem("Body")
bodytext = bodytext & vbCrLf
Call emailbody.AppendText(bodytext)

If Len(attachment) > 0 Then
Set objAttachment = emailbody.EmbedObject(1454, "", attachment)
End If

SendNotesMail = True

errorhandler:
SendNotesMail = False
Exit Function
End Function


As always watch for the line wrapping when you copy it across.

I hope this helps with your task.

The password is the password for the user / owner of the account which
is being used. You would need to modify this slightly to accomodate a
direct server connection if you wanted to completely "automate" your
process. This function is designed to work for a user at a terminal
that has Notes installed on their machine. If you want to check for
the presence / absence of Notes being installed you need to look for a
file called domobj.tlb I think.

Anyway, I hope this get you on your way.

Cheers

The Frog

Re: SendObject to Lotus Notes failing

am 23.11.2007 17:01:34 von Roy Tong

On Nov 23, 9:53 am, The Frog wrote:
> Hi Roy,
>
> I remember this lovely issue :-) Attempting to send information
> through Lotus Notes like this really is like beating your head against
> a wall. The easier way around the problem is to work with the lotus
> object model and create the email that way.
>
> If you go digging on the Lotus (IBM) website you can find a lot of
> free material on the Domino Object Model, and in particular one
> fantastic book (now freely downloadable as a pdf if I am not mistaken)
> called "COM Together with Domino" (item # SG24-5670-00). This has
> almost everything you will need to be able to play with Lotus through
> VB / VBA and is well worth the effort to get from the website.
>
> In the meantime I have some sample code for you to eyeball that you
> could modify to work for your needs:
>
> 1/ Make a reference to the Lotus Domino Objects under tools ->
> references
>
> Function SendNotesMail(password As String, subject As String, bodytext
> As String, Target As String, Optional attachment As String) As Boolean
>
> On Error GoTo errorhandler
>
> Dim Session As New NotesSession
> Dim MailDB As NotesDatabase
> Dim MailDoc As NotesDocument
> Dim objAttachment As Object
>
> Call Session.Initialize(password)
>
> Set notesdir = Session.GetDbDirectory("")
> Set MailDB = notesdir.OpenMailDatabase
>
> If MailDB.IsOpen = False Then
> MailDB.openmail
> End If
>
> Set MailDoc = MailDB.CreateDocument
>
> Call MailDoc.ReplaceItemValue("Form", "Memo")
> Call MailDoc.ReplaceItemValue("Subject", subject)
> 'Call MailDoc.ReplaceItemValue("Body", bodytext) ' this also works for
> just plain text with no attachments
> Call MailDoc.ReplaceItemValue("PostedDate", Now())
>
> Set emailbody = MailDoc.CreateRichTextItem("Body")
> bodytext = bodytext & vbCrLf
> Call emailbody.AppendText(bodytext)
>
> If Len(attachment) > 0 Then
> Set objAttachment = emailbody.EmbedObject(1454, "", attachment)
> End If
>
> SendNotesMail = True
>
> errorhandler:
> SendNotesMail = False
> Exit Function
> End Function
>
> As always watch for the line wrapping when you copy it across.
>
> I hope this helps with your task.
>
> The password is the password for the user / owner of the account which
> is being used. You would need to modify this slightly to accomodate a
> direct server connection if you wanted to completely "automate" your
> process. This function is designed to work for a user at a terminal
> that has Notes installed on their machine. If you want to check for
> the presence / absence of Notes being installed you need to look for a
> file called domobj.tlb I think.
>
> Anyway, I hope this get you on your way.
>
> Cheers
>
> The Frog

Hi Frog,

Thanks for the advice. I'll try this out.

Regards,

Roy