Before Mail Arrives Agent and DocumentContext

I’ve written an agent to act as an Auto-Responder to e-mails. I have it set up to run ‘Before New Mail Arrives’ and want to incude various pieces of the inbound e-mail in the response, namely the Subject and the e-mail body.When I run the agent, it fails with error 184: The variant does not contain a container. It seems that this is occurring when I try to get the Body text. I can get the Subject and the From address without issue and if I remove the reference to the Body field, the agent completes OK, apart from complaining about there being no Resume.

Is there an issue obtaining certain fields from the session.DocumentContext method?

I include the majority of the agent’s code below:

Sub Initialize

On Error Goto Ouch



Set session = New NotesSession



Set db=session.CurrentDatabase



Set docIn=session.DocumentContext



clientAddress = docIn.From(0)

clientSubject = docIn.Subject(0)

clientBody = Cstr(docIn.Body(0))		'<===ERROR OCCURS HERE

sDate = Cstr(Now)

’ Create outbound document

Set docOut=db.CreateDocument

docOut.From = "emergency@abcdefg.com"

docOut.SendTo = clientAddress

docOut.Subject = "Emergency order response"



sBodyText = "This is an automated response - please do not reply to this e-mail"

sBodyText = sBodyText & Chr$(10) & Chr$(10)

sBodyText = sBodyText & "We confirm receipt of your e-mail entitled " & clientSubject

sBodyText = sBodyText & " (attached below) at " & sDate & " UK time"

sBodyText = sBodyText & Chr$(10) & Chr$(10)

sBodyText = sBodyText & "We will action this request, subject to the request being complete and unambiguous, "

sBodyText = sBodyText & "as soon as possible"

sBodyText = sBodyText & Chr$(10) & Chr$(10)

sBodyText = sBodyText & "Original e-mail:"

sBodyText = sBodyText & Chr$(10) & Chr$(10)



docOut.Body = sBodyText

docOut.Send(False)



Goto Done

Ouch:

Print "Error " & Err() & ": " & Error()

Done:

End Sub

Subject: FIXED: Before Mail Arrives Agent and DocumentContext

OK, so the fix was that simple.

It seems that you can’t refer the Body field in the normal way i.e. doc.Body(0), as it’s not an array.

Cstr(doc.Body) seems to do the trick nicely.

Thanks anyway to anyone who might have been able to help!

Subject: Better do some reading up on Rich Text and what it is all about. You will lose all formatting, attachments etc. doing it this way.