Send mail to user after taking records from Active Directory

Hi ,Purpose of this code is to read data from Active directory and if cotact number is found blank for a user mail is sent .

This works fine when running this manually with my id or Scheduler Signer ID too but on scheduling it is getting stuck .

By default AD has read access to all those users listed in AD.

Is it like access is authenticating windowsid of the user who is running the code and not depending on agent signer id due to which this is running fine .

I presume there is some server to server access related issue OR Windows id is taking access to read data from AD or may be both.

Any suggestions will be appreciated.


Sub Initialize

Dim s As New NotesSession	

Dim db As NotesDatabase

Dim EM As String

Dim Emobile As String	

Dim objConnection As Variant 

Dim objCommand As Variant 

Dim objRecordSet As Variant 



Const ADS_SCOPE_SUBTREE = 2

Set db = s.CurrentDatabase  	

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"	

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = "SELECT * FROM 'LDAP://in.nam.ad.XYZ.com' WHERE userAccountControl= '512' OR userAccountControl= '544' "    ' Modify this line with your actual LDAP server name



Set objRecordSet = objCommand.Execute 	

count=objRecordSet.RecordCount	

If ( objRecordSet.RecordCount <> 0 ) Then		

	objRecordSet.MoveFirst		

	Do Until objRecordSet.EOF

		Print "Entering loop"

		Set objUser = GetObject(objRecordSet.Fields("ADsPath").Value)

		Print "Objuser set"

		EM=objUser.mail

		Emobile = objUser.homePhone	'Emergency phone number				

		Estaffname = objUser.firstname  'First Name required	

		

		If EM<>"" And  Emobile="" Then

										

			'Mail send code goes here'''''''''''''''''''''''''''''''''''''''''''''			

			Dim richStyle As NotesRichTextStyle

			Set richStyle = s.CreateRichTextStyle

			Set memo = New NotesDocument( db )				

			Dim rtitem As New NotesRichTextItem(memo, "Body")		

			memo.Form="Memo"

			memo.Subject ="TEST"					

			Call rtitem.AppendText("TEST MAIL") 	

			memo.SendTo = EM

			Call memo.Send(True)						

		End If			

		objRecordSet.MoveNext			

	Loop	

	objRecordSet.close

		End If					

	Exit Sub

End Sub


Subject: Send mail to user after taking records from Active Directory

What does happen. Do you get any error? Does any of the debug prints show in the log? Try putting some more print before and after count=objRecordSet.RecordCount to see if it is timing out.

What rights does the signer of the agent have. You likely need unrestricted access

Subject: RE: Send mail to user after taking records from Active Directory

For Active directory by default read access is available only to those windows ids which are available in Active Directory.

When scheduler is running no windows id is there for Agent signer id when running on server as this is causing issue .

As when code was run using signer id manually code has taken windows id and signer was able read data from AD.

Subject: RE: Send mail to user after taking records from Active Directory

Please advise on this if any one has done this.On scheduling its giving error on log.nsf as

Error is : Operation is disallowed in this session at line number : 16

Line number 16 sets connection:

Set objConnection = CreateObject(“ADODB.Connection”)

Is there any server to server access issue (Db is on server 1 and AD is on anoter server) .

There is some connectivity issue looks like when scheduled

Secondly I have added this connection id and pasword now too before 'objConnection.Open “Active Directory Provider”

still facing same issue.

objConnection.Properties(“User ID”) = “xyz”

objConnection.Properties(“Password”) = “dd”

Really appreciate any help in this regard.

Subject: RE: Send mail to user after taking records from Active Directory

This technote might help you

http://www-01.ibm.com/support/docview.wss?uid=swg21106729

Subject: RE: Send mail to user after taking records from Active Directory

Thanks alot Scarlet.This really helped and now same is working fine on schedule , only change in option was rquired on security tab to ‘Allow restricted operations’.