Wrox Programmer Forums
|
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
 
Old August 13th, 2003, 04:15 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old August 13th, 2003, 04:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old August 13th, 2003, 05:35 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old August 13th, 2003, 06:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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?
 
Old August 13th, 2003, 06:11 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're right, the e-mails have to be sent internally. I've tried sending a mail to NTUsername and [email protected], neither work.

 
Old August 13th, 2003, 06:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry, if Exchange doesn't recognise the NT user name I'm out of ideas.
 
Old August 13th, 2003, 06:38 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old August 13th, 2003, 07:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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:
Quote:
quote:
Collaboration Data Objects (CDO) messaging has additional capabilities with Microsoft Exchange 2000 Server. To send messages using Exchange (through the Exchange mail submission URI), you set the http://schemas.microsoft.com/cdo/con...tion/sendusing field to cdoSendUsingExchange in the Configuration object of the Message object. Similarly, you set the http://schemas.microsoft.com/cdo/con...tion/postusing field to cdoPostUsingExchange to post using Exchange.
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
 
Old August 13th, 2003, 08:23 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)

 
Old August 13th, 2003, 10:16 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
setting from address in outlook mail item bishnupokhrel Pro VB 6 1 January 26th, 2011 10:28 AM
Read the mail address from the web page gmbalaa General .NET 0 September 14th, 2007 04:12 AM
Changing the senders email address in the mail() rinventive Beginning PHP 1 May 23rd, 2006 10:24 PM
E-mail Address Changes Ben Horne Forum and Wrox.com Feedback 1 April 1st, 2004 04:43 PM
Verify for Valid E-mail address eapsokha Classic ASP Professional 2 February 24th, 2004 12:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.