theniteowl
Programmer
Hi All,
I have an HTA app that allows the entry of a persons name or Employee ID number, looks that information up on the exchange server and if valid sends an email to that ID.
Apparently though what it does is translates the ID number if that was used into a name, or takes the name directly and checks to see if it exists on the exchange server.
Most times this is fine but here is the problem.
If we have two people with the same name, the script is only validating that the name exists, it is not returning a reference to the actual person I am trying to look up.
For instance. User 1 named John Doe, ID# AA12345 with a Display Name of Doe, John.
User 2 named John Doe, ID# BB54321 with a display name of Doe, John K.
Both people have different email addresses and display names but the first and last names are the same.
When the script validates is DOES find someone with the first/last name but when it tries to send it puts the last, first into the TO line and that will not resolve because there are multiple options for that name.
How can I get it to resolve in this case?
Or even just use the ID# to return the email address and insert that in the TO line since that will not have to resolve.
Help?
Here is my code.
Paranoid? ME?? WHO WANTS TO KNOW????
I have an HTA app that allows the entry of a persons name or Employee ID number, looks that information up on the exchange server and if valid sends an email to that ID.
Apparently though what it does is translates the ID number if that was used into a name, or takes the name directly and checks to see if it exists on the exchange server.
Most times this is fine but here is the problem.
If we have two people with the same name, the script is only validating that the name exists, it is not returning a reference to the actual person I am trying to look up.
For instance. User 1 named John Doe, ID# AA12345 with a Display Name of Doe, John.
User 2 named John Doe, ID# BB54321 with a display name of Doe, John K.
Both people have different email addresses and display names but the first and last names are the same.
When the script validates is DOES find someone with the first/last name but when it tries to send it puts the last, first into the TO line and that will not resolve because there are multiple options for that name.
How can I get it to resolve in this case?
Or even just use the ID# to return the email address and insert that in the TO line since that will not have to resolve.
Help?
Here is my code.
Code:
<script language="vbscript">
Function SendEmail(name)
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
Dim thisdate
thisdate = Date
Dim Pos
Dim SenderFullName
Dim SenderLastName
Dim SenderFirstName
Dim RecipientFullName
Dim RecipientLastName
Dim RecipientFirstName
ToAddress = name
MessageSubject = "my subject"
MessageBody = "Message body"
MessageBody = MessageBody & chr(13) & chr(13) & "Thank you for your attention to this matter." & chr(13)
On Error Resume Next
' Assume success
fSuccess = True
Set ol = GetObject("", "Outlook.application")
' If Outlook is NOT Open, then there will be an error.
' Attempt to open Outlook
If Err.Number > 0 Then
Err.clear
Set ol = CreateObject("Outlook.application")
If Err.Number > 0 Then
MsgBox "Could not create Outlook object", vbCritical
fSuccess = False
Exit Function
End If
End If
' If we've made it this far, we have an Outlook App Object
' Now, set the NameSpace object to MAPI Namespace
Set ns = ol.GetNamespace("MAPI")
ns.logon "","",true,false
If Err.Number > 0 Then
MsgBox "Could not create NameSpace object", vbCritical
fSuccess = False
Exit Function
End If
If fsuccess = True Then
' Create the mail item and populate it with data
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
SenderFullName = ns.CurrentUser.Name
Pos = InStr(1, SenderFullName, ",", vbTextCompare)
SenderLastName = Trim(Left(SenderFullName, Pos - 1))
SenderFirstName = Right(SenderFullName, Len(SenderFullName) - (Pos + 1))
' validate the recipient.
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "Invalid recipient ID or name, please re-enter."
Else
resetid()
newMail.Recipients.Add(myRecipient)
RecipientFullName = myRecipient
Pos = InStr(1, RecipientFullName, ",", vbTextCompare)
RecipientLastName = Trim(Left(RecipientFullName, Pos - 1))
RecipientFirstName = Right(RecipientFullName, Len(RecipientFullName) - (Pos + 1))
Message = FormatDateTime(Now(), 1) & "<br>" & "<br>" & RecipientFirstName & " " & RecipientLastName & "<br>" & "<br>" & MessageBody & "<br>" & "<br>"
Message = Message & SenderFirstName & " " & SenderLastName & "<br>"
newMail.HTMLBody = Message & "<br>"
newMail.Display 'Un-comment this line and comment out the newMail.Send line if you want to review the message before sending.
' newMail.Send
MsgBox "Your message has been sent."
End If
End If
' Close out our objects.
Set ol = Nothing
Set ns = Nothing
End Function
</script>
Paranoid? ME?? WHO WANTS TO KNOW????