 |
| ASP CDO As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP CDO section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 13th, 2003, 04:15 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Resolving NTlogins to an e-mail address
I'm currently doing my summerjob at a company and I need to be able to resolve an NTaccount to its respective e-mail address using ASP. I assume it's easy, but I haven't been able to find any information for this.
Any help would really be appreciated
|
|

August 13th, 2003, 04:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You should be able to get it out of the Active Directory (search for ADSI), try something like this:
Code:
Function GetUserEMail()
Dim sFullUser
Dim objUser
sFullUser = Trim(Request.ServerVariables ("LOGON_USER"))
if Len(sFullUser) = 0 then
GetUserEMail = "Disable anonymous access for this code to work."
Else
Set objUser = GetObject("WinNT://" & Replace(sFullUser, "\", "/"))
GetUserEMail = objUser.EmailAddress
Set objUser = Nothing
End if
End Function
|
|

August 13th, 2003, 05:35 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx for your reply! The function returns an empty string. I suppose this means the e-mail address isn't stored in the active directory or I'm overlooking something.
Is there another way to lookup an e-mail address? Maybe by using a connection to the exchange server? I read something about resolving a name to an e-mail address using CDO, but I haven't found an example of implementation yet.
|
|

August 13th, 2003, 06:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I assume you're just trying to send emails internally within your company? Have you tried just sending a mail to NTuserName and letting the mail server sort it out?
|
|

August 13th, 2003, 06:11 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You're right, the e-mails have to be sent internally. I've tried sending a mail to NTUsername and [email protected], neither work.
|
|

August 13th, 2003, 06:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Sorry, if Exchange doesn't recognise the NT user name I'm out of ideas. 
|
|

August 13th, 2003, 06:38 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You've been great help though. One more thing, perhaps I used the wrong way to send mail? I used:
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "fromuser"
objEmail.To = "ntuser"
objEmail.Subject = "test"
objEmail.Textbody = "test"
objEmail.send
Maybe I'm not using exchange but SMTP this way?
|
|

August 13th, 2003, 07:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Quote:
quote:Originally posted by omen88
...Maybe I'm not using exchange but SMTP this way?
|
Interesting thought. CDO isn't my strong point, but I found this quote and code snippet in MSDN:
and this code which is VB but should be easy enough to convert to ASP, you'll just need to get numeric values for the constants used such as cdoSendUsingExchange
Code:
Sub SendMessageUsingExchange(sTo As String, sFrom As String, sSubject As String, sText As String, sMailboxURL As String)
Dim iMsg As New CDO.Message
Dim iBp As CDO.IBodyPart
Dim Flds As ADODB.Fields
Dim Conn As New ADODB.Connection
Dim Stm As ADODB.Stream
Conn.Provider = "ExOLEDB.DataSource"
Conn.Open sMailboxURL
Dim iConf As New CDO.Configuration
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod) = cdoSendUsingExchange
Flds(cdoMailboxURL) = sMailboxURL
Flds(cdoActiveConnection) = Conn
Flds.Update
With iMsg
Set .Configuration = iConf
.To = sTo
.From = sFrom
.Subject = sSubject
.TextBody = sText
Set iBp = .AddAttachment("c:\wordfile.doc")
Set Stm = .GetStream
Stm.SaveToFile "c:\mysavedmessage.eml", adSaveCreateOverWrite
.Send
End With
End Sub
hth
Phil
|
|

August 13th, 2003, 08:23 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx! I'm sure going to check this out as soon as I get this other stuff finished. (programming with deadlines and other jobs isn't really a good way to produce decent code)
|
|

August 13th, 2003, 10:16 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Damn it! I've converted the code and set the option using exchange, but still it can't mail using only the NTlogin.
Thanx for your help though!!
|
|
 |