bsharath
asked on
Place forward email id for all users in a file.
Hi,
I have a txt file which has the NT login or email id which ever can be easy to create the script.
A way to forward mails according to the user
Ex:
Sharath@plc.com Sharath@the.com
Need to set the forward to each user next to it.
I have 300 users for whome i need to forward to different mail id's.
Regards
Sharath
I have a txt file which has the NT login or email id which ever can be easy to create the script.
A way to forward mails according to the user
Ex:
Sharath@plc.com Sharath@the.com
Need to set the forward to each user next to it.
I have 300 users for whome i need to forward to different mail id's.
Regards
Sharath
ASKER
I need to forward mails for 200 users to a different account.
Is there a easy way of setting this.
Each user to be forwarded to different mail id's
Like Sharath@plc.com mails to be forwarded to Sharath@the.com and so on....
Ex:
Sharath@plc.com Sharath@the.com
Is there a easy way of setting this.
Each user to be forwarded to different mail id's
Like Sharath@plc.com mails to be forwarded to Sharath@the.com and so on....
Ex:
Sharath@plc.com Sharath@the.com
Exchange server? same users names diffrent domains? or completely diffrent people. Recipient polcy to set an alias feasable?
Where to you normally forward the mails in the exchange and which attribute?
ASKER
Each user has a option to forward a copy of his mail to any internal or external email id.
So that is what i want to do.Each user in the file has to send a mail of his to his individual private email id.Like yahoo or hotmail.
So that is what i want to do.Each user in the file has to send a mail of his to his individual private email id.Like yahoo or hotmail.
They will br forwarding this or you configure this. If yes where do you configure this?
ASKER
In users properties > Exchange general > Delivery options > Forward to.
Is the place where i need to assign the new email address.
So need a script which can do this...
Is the place where i need to assign the new email address.
So need a script which can do this...
ASKER
Any help on this chandru...
Sharath, see this tutorial:
http://www.msexchange.org/tutorials/MF015.html
It seems that you need to create the "contact" object for the external person, and then forward the internal person's mail to that external person.
If these external contacts are not already created, then they need to be created. Then I think we could use the Distinguished Name of that external Contact, and add it to the User's altRecipient or ForwardTo property:
strExternalContactDN = "CN=ExtContact,OU=Contacts ,DC=domain ,DC=com"
Set objUser = GetObject("LDAP://" & SourceUser)
objUser.Put "AltRecipient", strExternalContactDN
' OR MAYBE ALSO
' objUser.Put "forwardTo", strExternalContactDN
objUser.SetInfo
Regards,
Rob.
http://www.msexchange.org/tutorials/MF015.html
It seems that you need to create the "contact" object for the external person, and then forward the internal person's mail to that external person.
If these external contacts are not already created, then they need to be created. Then I think we could use the Distinguished Name of that external Contact, and add it to the User's altRecipient or ForwardTo property:
strExternalContactDN = "CN=ExtContact,OU=Contacts
Set objUser = GetObject("LDAP://" & SourceUser)
objUser.Put "AltRecipient", strExternalContactDN
' OR MAYBE ALSO
' objUser.Put "forwardTo", strExternalContactDN
objUser.SetInfo
Regards,
Rob.
ASKER
Rob i have the contacts already ready.
I have 200 users who always be on travel.Even though the OWA is available for them to access.By chance there is a problem .I need it to be forwarded to some hotmail or yahoo id's
So what i have done is created a Contact and put in this external email id there.Now i just need to put in this email id to the forward tab.
I have 200 users who always be on travel.Even though the OWA is available for them to access.By chance there is a problem .I need it to be forwarded to some hotmail or yahoo id's
So what i have done is created a Contact and put in this external email id there.Now i just need to put in this email id to the forward tab.
ASKER
WISH YOU AND YOUR FAMILY A VERY HAPPY NEW YEAR.Rob and Chandru
How was the 31st night?
How was the 31st night?
OK, so as you already have these contacts, I assume you have tested that assigning an external contact as a forwarding address works? If so, then we can use the email address for a user to find their object, and assign the contact with the email address next to them in the file. So in your file if you have:
Sharath@plc.com;Sharath@th e.com
separate by a semi-colon ( ; ), then the first would be the internal user, the second would be the external user. Hopefully we would be able to get that to work.
HAPPY NEW YEAR to you as well! It's 2pm on January 2nd, so I've had some time to recover! LOL!
Regards,
Rob.
Sharath@plc.com;Sharath@th
separate by a semi-colon ( ; ), then the first would be the internal user, the second would be the external user. Hopefully we would be able to get that to work.
HAPPY NEW YEAR to you as well! It's 2pm on January 2nd, so I've had some time to recover! LOL!
Regards,
Rob.
ASKER
Yes Rob i have a file just as listed by you ready with the internal and external email id's
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rob i get this...
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Set Forwards.vbs
Line: 22
Char: 19
Error: The specified directory service attribute or value does not exist.
Code: 8007200A
Source: (null)
-------------------------- -
OK
-------------------------- -
As said i tried like this
strIntUserADsPath = Get_LDAP_User_Properties(" user", "mail", strInternalEmail, "ADsPath")
If InStr(strIntUserADsPath, "LDAP://") > 0 Then
strExtUserADsPath = Get_LDAP_User_Properties(" contact", "mail", strExternalEmail, "ADsPath")
If InStr(strExtUserADsPath, "LDAP://") > 0 Then
Set objIntUser = GetObject(strIntUserADsPat h)
objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
'objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
objIntUser.SetInfo
and then
strIntUserADsPath = Get_LDAP_User_Properties(" user", "mail", strInternalEmail, "ADsPath")
If InStr(strIntUserADsPath, "LDAP://") > 0 Then
strExtUserADsPath = Get_LDAP_User_Properties(" contact", "mail", strExternalEmail, "ADsPath")
If InStr(strExtUserADsPath, "LDAP://") > 0 Then
Set objIntUser = GetObject(strIntUserADsPat h)
' objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
'objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
objIntUser.SetInfo
Is that corect.For both i get the same error.
--------------------------
Windows Script Host
--------------------------
Script: C:\Set Forwards.vbs
Line: 22
Char: 19
Error: The specified directory service attribute or value does not exist.
Code: 8007200A
Source: (null)
--------------------------
OK
--------------------------
As said i tried like this
strIntUserADsPath = Get_LDAP_User_Properties("
If InStr(strIntUserADsPath, "LDAP://") > 0 Then
strExtUserADsPath = Get_LDAP_User_Properties("
If InStr(strExtUserADsPath, "LDAP://") > 0 Then
Set objIntUser = GetObject(strIntUserADsPat
objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
'objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
objIntUser.SetInfo
and then
strIntUserADsPath = Get_LDAP_User_Properties("
If InStr(strIntUserADsPath, "LDAP://") > 0 Then
strExtUserADsPath = Get_LDAP_User_Properties("
If InStr(strExtUserADsPath, "LDAP://") > 0 Then
Set objIntUser = GetObject(strIntUserADsPat
' objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
'objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
objIntUser.SetInfo
Is that corect.For both i get the same error.
Yes, the first one to try is like this:
objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
'objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
and the second like this
'objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
One tries the AltRecipient value, the other tries the forwardTo value.....
I don't have exchange so I can't test this....I'll look for another attrbute.....
Rob.
objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
'objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
and the second like this
'objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
objIntUser.Put "forwardTo", Replace(strExtUserDN, "LDAP://", "")
One tries the AltRecipient value, the other tries the forwardTo value.....
I don't have exchange so I can't test this....I'll look for another attrbute.....
Rob.
ASKER
I tried both Rob but get the same error.
Maybe try
objIntUser.Put "AltRecipient", Replace(strExtUserADsPath, "LDAP://", "")
or
objIntUser.Put "forwardTo", Replace(strExtUserADsPath, "LDAP://", "")
or
objIntUser.Put "AltRecipient", strExtUserADsPath
or
objIntUser.Put "forwardTo", strExtUserADsPath
Regards,
Rob.
objIntUser.Put "AltRecipient", Replace(strExtUserADsPath,
or
objIntUser.Put "forwardTo", Replace(strExtUserADsPath,
or
objIntUser.Put "AltRecipient", strExtUserADsPath
or
objIntUser.Put "forwardTo", strExtUserADsPath
Regards,
Rob.
Or maybe
objIntUser.altRecipient = Replace(strExtUserADsPath, "LDAP://", "")
Rob.
objIntUser.altRecipient = Replace(strExtUserADsPath,
Rob.
ASKER
If i get a Finish box does it mean that its done and may take some time to reflect?
If you get no error, then yes, it should have done something with the Forward To property (hopefully). Can you check the User Account in the AD and see if it has been set?
Rob.
Rob.
ASKER
Final script that worked great...
'=======================
strInputFile = "EmailForwards.txt"
Const intForReading = 1
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objInputFile = objFSO.OpenTextFile(strInp utFile, intForReading, False)
While Not objInputFile.AtEndOfStream
strIntUserADsPath = ""
strExtUserDN = ""
arrAddresses = Split(objInputFile.ReadLin e, ";")
strInternalEmail = arrAddresses(0)
strExternalEmail = arrAddresses(1)
strIntUserADsPath = Get_LDAP_User_Properties(" user", "mail", strInternalEmail, "ADsPath")
If InStr(strIntUserADsPath, "LDAP://") > 0 Then
strExtUserADsPath = Get_LDAP_User_Properties(" contact", "mail", strExternalEmail, "ADsPath")
If InStr(strExtUserADsPath, "LDAP://") > 0 Then
Set objIntUser = GetObject(strIntUserADsPat h)
'objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
objIntUser.Put "AltRecipient", Replace(strExtUserADsPath, "LDAP://", "")
objIntUser.SetInfo
Else
MsgBox "Could not find an external contact with an email address of " & strExternalMail
End If
Else
MsgBox "Could not find an internal user account with an email address of " & strInternalEmail
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objFSO = Nothing
MsgBox "Finished."
Function Get_LDAP_User_Properties(s trObjectTy pe, strSearchField, strObjectToGet, strCommaDelimProps)
' This is a custom function that connects to the Active Directory, and returns the specific
' Active Directory attribute value, of a specific Object.
' strObjectType: usually "User" or "Computer"
' strSearchField: the field by which to seach the AD by. This acts like an SQL Query's WHERE clause.
' It filters the results by the value of strObjectToGet
' strObjectToGet: the value by which the results are filtered by, according the strSearchField.
' For example, if you are searching based on the user account name, strSearchField
' would be "samAccountName", and strObjectToGet would be that speicific account name,
' such as "jsmith". This equates to "WHERE 'samAccountName' = 'jsmith'"
' strCommaDelimProps: the field from the object to actually return. For example, if you wanted
' the home folder path, as defined by the AD, for a specific user, this would be
' "homeDirectory". If you want to return the ADsPath so that you can bind to that
' user and get your own parameters from them, then use "ADsPath" as a return string,
' then bind to the user: Set objUser = GetObject("LDAP://" & strReturnADsPath)
' Now we're checking if the user account passed may have a domain already specified,
' in which case we connect to that domain in AD, instead of the default one.
If InStr(strObjectToGet, "\") > 0 Then
arrGroupBits = Split(strObjectToGet, "\")
strDC = arrGroupBits(0)
strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")
strObjectToGet = arrGroupBits(1)
Else
' Otherwise we just connect to the default domain
Set objRootDSE = GetObject("LDAP://RootDSE" )
strDNSDomain = objRootDSE.Get("DefaultNam ingContext ")
'strDNSDomain = objRootDSE.Get("RootDomain NamingCont ext")
End If
strBase = "<LDAP://" & strDNSDomain & ">"
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Comman d")
Set adoConnection = CreateObject("ADODB.Connec tion")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio n = adoConnection
' Filter on user objects.
'strFilter = "(&(objectCategory=person) (objectCla ss=user))"
strFilter = "(&(objectClass=" & strObjectType & ")(" & strSearchField & "=" & strObjectToGet & "))"
' Comma delimited list of attribute values to retrieve.
strAttributes = strCommaDelimProps
arrProperties = Split(strCommaDelimProps, ",")
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
' Define the maximum records to return
adoCommand.Properties("Pag e Size") = 100
adoCommand.Properties("Tim eout") = 30
adoCommand.Properties("Cac he Results") = False
MsgBox strQuery
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
strReturnVal = ""
Do Until adoRecordset.EOF
' Retrieve values and display.
For intCount = LBound(arrProperties) To UBound(arrProperties)
If strReturnVal = "" Then
strReturnVal = adoRecordset.Fields(intCou nt).Value
Else
strReturnVal = strReturnVal & VbCrLf & adoRecordset.Fields(intCou nt).Value
End If
Next
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Get_LDAP_User_Properties = strReturnVal
End Function
'=======================
Thanks a lot Rob
'=======================
strInputFile = "EmailForwards.txt"
Const intForReading = 1
Set objFSO = CreateObject("Scripting.Fi
Set objInputFile = objFSO.OpenTextFile(strInp
While Not objInputFile.AtEndOfStream
strIntUserADsPath = ""
strExtUserDN = ""
arrAddresses = Split(objInputFile.ReadLin
strInternalEmail = arrAddresses(0)
strExternalEmail = arrAddresses(1)
strIntUserADsPath = Get_LDAP_User_Properties("
If InStr(strIntUserADsPath, "LDAP://") > 0 Then
strExtUserADsPath = Get_LDAP_User_Properties("
If InStr(strExtUserADsPath, "LDAP://") > 0 Then
Set objIntUser = GetObject(strIntUserADsPat
'objIntUser.Put "AltRecipient", Replace(strExtUserDN, "LDAP://", "")
' OR MAYBE ALSO
objIntUser.Put "AltRecipient", Replace(strExtUserADsPath,
objIntUser.SetInfo
Else
MsgBox "Could not find an external contact with an email address of " & strExternalMail
End If
Else
MsgBox "Could not find an internal user account with an email address of " & strInternalEmail
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objFSO = Nothing
MsgBox "Finished."
Function Get_LDAP_User_Properties(s
' This is a custom function that connects to the Active Directory, and returns the specific
' Active Directory attribute value, of a specific Object.
' strObjectType: usually "User" or "Computer"
' strSearchField: the field by which to seach the AD by. This acts like an SQL Query's WHERE clause.
' It filters the results by the value of strObjectToGet
' strObjectToGet: the value by which the results are filtered by, according the strSearchField.
' For example, if you are searching based on the user account name, strSearchField
' would be "samAccountName", and strObjectToGet would be that speicific account name,
' such as "jsmith". This equates to "WHERE 'samAccountName' = 'jsmith'"
' strCommaDelimProps: the field from the object to actually return. For example, if you wanted
' the home folder path, as defined by the AD, for a specific user, this would be
' "homeDirectory". If you want to return the ADsPath so that you can bind to that
' user and get your own parameters from them, then use "ADsPath" as a return string,
' then bind to the user: Set objUser = GetObject("LDAP://" & strReturnADsPath)
' Now we're checking if the user account passed may have a domain already specified,
' in which case we connect to that domain in AD, instead of the default one.
If InStr(strObjectToGet, "\") > 0 Then
arrGroupBits = Split(strObjectToGet, "\")
strDC = arrGroupBits(0)
strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")
strObjectToGet = arrGroupBits(1)
Else
' Otherwise we just connect to the default domain
Set objRootDSE = GetObject("LDAP://RootDSE"
strDNSDomain = objRootDSE.Get("DefaultNam
'strDNSDomain = objRootDSE.Get("RootDomain
End If
strBase = "<LDAP://" & strDNSDomain & ">"
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Comman
Set adoConnection = CreateObject("ADODB.Connec
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio
' Filter on user objects.
'strFilter = "(&(objectCategory=person)
strFilter = "(&(objectClass=" & strObjectType & ")(" & strSearchField & "=" & strObjectToGet & "))"
' Comma delimited list of attribute values to retrieve.
strAttributes = strCommaDelimProps
arrProperties = Split(strCommaDelimProps, ",")
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
' Define the maximum records to return
adoCommand.Properties("Pag
adoCommand.Properties("Tim
adoCommand.Properties("Cac
MsgBox strQuery
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
strReturnVal = ""
Do Until adoRecordset.EOF
' Retrieve values and display.
For intCount = LBound(arrProperties) To UBound(arrProperties)
If strReturnVal = "" Then
strReturnVal = adoRecordset.Fields(intCou
Else
strReturnVal = strReturnVal & VbCrLf & adoRecordset.Fields(intCou
End If
Next
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Get_LDAP_User_Properties = strReturnVal
End Function
'=======================
Thanks a lot Rob
Ah, great, so it was this one that did it:
objIntUser.Put "AltRecipient", Replace(strExtUserADsPath, "LDAP://", "")
Very good.
Regards,
Rob.
objIntUser.Put "AltRecipient", Replace(strExtUserADsPath,
Very good.
Regards,
Rob.
regards
Chandru