Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_cdo thread: SMTP Address of Exchange Service Account


Message #1 by "Anand [EG-GOE]" <anand@s...> on Tue, 31 Jul 2001 08:50:49 +0800
Dear All,  Below is the code that i use to trap the SMTP address of a user

in exchange. It works fine all the user in exchange server, but does not

work only for the service account. Can anyone let me know why?



*******Code Starts Here************



Const ADS_SID_WINNT_PATH = 5 'Global Variable

Const ADS_SID_HEXSTRING = 1 'Global Variable



Dim strLogonAccount

Dim strDirUsr

Dim strDirUsrPwd

Dim strLogonUsrDomain

Dim strServer



strLogonAccount="TESTPC_2\Service" 'If you change to any user other

than the service, it works fine. I can get the SMTP address.

strDirUsr = "TESTPC_2\testuser"

strDirUsrPwd="password"

strServer="testpc5"



Function AMSmtp(inszMailbox, inszMailServer)

        AMSmtp = GetSmtp(strServer, GetSid(strLogonAccount))

End Function



Function GetSid(NTstrLogonAccount)

  Dim Sid

  NTstrLogonAccount = Replace(Trim(NTstrLogonAccount), "\", "/")

  Set Sid = Server.CreateObject("ADsSID")

  On Error Resume Next

  Sid.SetAs ADS_SID_WINNT_PATH, "WinNT://" & NTstrLogonAccount

  if Err Then Exit Function

  GetSid = Sid.GetAs(ADS_SID_HEXSTRING)

End Function



Function GetSmtp(strServer, sid)



  Dim q, Connection, Command, rs

  set Connection = Server.Createobject("ADODB.Connection")

  Connection.Provider = "ADSDSOObject"

  Connection.Properties("User ID") = strDirUsr

  Connection.Properties("Password") = strDirUsrPwd

  Connection.Properties("Encrypt Password") = True

  Connection.Open "ADs Provider"

  q = "<LDAP://" & strServer & ">;(&(objectClass=person)(Assoc-NT-Account="

& sid & "));mail"

  Set Command = Server.Createobject("ADODB.Command")

  Command.ActiveConnection = Connection

  Command.CommandText = q

  Set rs = Command.Execute

  if not rs.eof then GetSmtp = rs(0).value

  rs.close

  connection.close

  Set Connection = Nothing

  Set Command = Nothing

  Set rs = Nothing

End Function

</SCRIPT>



***CODE ENDS HERE*****



By the by, I use this function call in my ASP page.



Thanks and Regards



Anand

SAPURA ADVANCED SYSTEMS

TECHNOLOGY PARK, MALAYSIA




  Return to Index