Send response from url to sender

Hi ,

Please help me to do this.

Requirement is , when a user sends mail based on the mail subject I need to call a url and then read response returned from that url and send the same to the sender on mail.

Plan is to create an agent and schedule it ‘After new mail arrives’

Not worked on urls before so unable to get any idea.

Thanks

Seema

Subject: Send response from url to sender

I am using a mail in database template and sending mail to mail in database id using the code below.

When I tried to call this on hotspot button without running / taking doc part and directly reading url and sending a response mail with reponse returned from url , this worked fine and I got response mail.

  1. When I tried to run this on event ‘After new mail arrives’ this is not working - As per requirement this needs to run when new mail arrives.

  2. When I did run this manually from designer -Right clicking and Run then I got a response mail and same works fine

Is there any other way I can implement this or any correction required in this code.

Any help is really appreciated.

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection	

Dim doc As NotesDocument

Dim ritem As NotesRichTextItem



Dim vWinHTTP As Variant 

Dim SMSAPIKey As String

Dim sMessage As String

Dim sURL As String





SMSAPIKey ="http://10.31.8.52/ABCotpweb/default.aspx"

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments



Set doc = collection.GetFirstDocument()

While Not(doc Is Nothing)

	If doc.subject(0)="TEST" Then 

		doc.Subject = "test response" 

		Set ritem = New NotesRichTextItem( doc, "Body")

		Call ritem.AddNewLine( 1 )	

		

		Set vWinHTTP = CreateObject("WinHTTP.WinHTTPRequest.5.1") 

		

		Call vWinHTTP.SetProxy(HTTPREQUEST_PROXYSETTING_PROXY , "10.31.8.34:8080", "10.*")

		Call vWinHTTP.Open( "GET", SMSAPIKey , False )        

		Call vWinHTTP.Send()

		

		sResponse = vWinHTTP.ResponseText

		Set vWinHTTP = Nothing     

		ritem.appendtext("Response is - "+sResponse ) 

         'SendTo=doc.from(0)						

		Call doc.Send( False, "ABCD@in.xyz.com")

			

		Set vWinHTTP = Nothing		

	End If	

	Call session.UpdateProcessedDoc( doc )

	Set doc = collection.GetNextDocument(doc)

Wend

End Sub

Subject: RE: Send response from url to sender

  1. When I tried to run this on event ‘After new mail arrives’>> this is not working - As per requirement this needs to run

when new mail arrives.

What do you mean by “not working”? What happens?

Also, what type of server do you have? Is it a Windows server? Is the WinHTTP.WinHTTPRequest.5.1 object available on your server? (See WinHTTP Versions - Win32 apps | Microsoft Learn)

  1. When I did run this manually from designer -Right clicking and Run then I got a response mail but when I tried opening that response mail I got error as ’ A stored form can not contain computed subforms’

You are calling docM.Send(True). The True argument specifies that you want to use the store-form-in-document feature. Why are you doing that? Why do you need to send a stored form? It looks like you are using the ordinary Memo form, which should already exist in everybody’s mailbox, so unless you have customized the form and you don’t want to update the mail template there’s no reason that I can think of for this.

-rich

Subject: RE: Send response from url to sender

Thanks Rich.

This helped . Now I’m sending the doc directly .

So now code works fine when I’m running this manually updated the same in my post above.

Need to check now on option 1 .

Agent Log is not showing that it has run.

Yes WinHTTP.WinHTTPRequest.5.1 is available on server.

As now code is running fine manually will this work fine again when set as per option 1.