[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

Agent crashes Notes from COM

I have an agent which processes email and I want to call from vb.net. I have attached the code from the agent and the code from the button click in .net.

Running and debugging the agent from within Notes, the agent works fine. When I try from .net Notes crashes and dumps a 2mb log file.

I can only conclude that either:
1. The code is processed too fast outside of the debugger
2. There is a security issue.

Thanks in advance.
This is the code in .NET.
Dim lcl_session As Domino.NotesSession
Dim lcl_session_database As Domino.NotesDatabase
Dim doc As NotesDocument
Dim html_email_agent As NotesAgent
lcl_session = New Domino.NotesSession()
lcl_session_database = lcl_session.GetDatabase("", "mail\chafford100.nsf")
If lcl_session_database.IsOpen() = False Then
End If
doc = lcl_session_database.CreateDocument
doc.ReplaceItemValue("Form", "Memo")
doc.ReplaceItemValue("PostedDate", Now())
doc.ReplaceItemValue("SendTo", "abc@xyz.com")
doc.ReplaceItemValue("Subject", "HTML email 1")
doc.ReplaceItemValue("From", "def.ggg@chafford.com")
doc.ReplaceItemValue("Body", "This is the test subject")
doc.SaveMessageOnSend = True
doc.Save(True, False)
html_email_agent = lcl_session_database.GetAgent("TestAgent1234") 
If IsNothing(html_email_agent) = False Then
    MsgBox("Agent not found")
End If
'This is the agent:
Sub Initialize
	Dim notes_session As notessession
	Dim notes_database As notesdatabase
	Dim existing_document As notesdocument
	Dim mail_subject As Variant
	Dim recipient_address As Variant 
	Dim html_email_body As Variant
	Dim agent As NotesAgent
	Dim mail_document As NotesDocument 
	'Set up the Current Database.
	Set notes_session = New NotesSession 
	Set notes_database = notes_session.currentdatabase
	'Pull up the document that was created prior to this call
	Set agent = notes_session.CurrentAgent
	Set existing_document = notes_database.GetDocumentByID(agent.ParameterDocID)
	'Create a new document. We will mail this.
	Set mail_document = notes_database.CreateDocument
	'Grab the recipients, subject and body from the existing mail.
	recipient_address = existing_document.GetItemValue("SendTo")
	mail_subject = existing_document.GetItemValue("Subject")
	html_email_body = existing_document.GetItemValue("Body")
	mail_document.SaveMessageOnSend = True
	Call mail_document.ReplaceItemValue("Form", "Memo")
	Call mail_document.ReplaceItemValue("PostedDate", Now())
	Call mail_document.ReplaceItemValue("SendTo", recipient_address)
	Call mail_document.ReplaceItemValue("Subject", mail_subject)
	Call mail_document.ReplaceItemValue("Body",html_email_body)
	Call mail_document.ComputeWithForm(True,False)
	'Send the email
	Call mail_document.send(False)
	'Remove the document which we created to pass the data.
	Call existing_document.Remove(True)
End Sub

Open in new window

1 Solution
Is this on  server or a Notes client.try notes.notessession rather than domino.

ALso R5 is ancient and no longer supported so it may be tough trying to fully debug.

chafford100Author Commented:
Spot on with your suggestion.

Actually just to complete the solution there is a need to late bind everything so I changed the .net code to be CreateObject() etc. etc. When I ran the code the agent worked first time.


Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now