DESCRIPTION
This function will change the default SMTP address for a given user and new SMTP address.
Note This code may use functions from the Active Roles Script Policy Best Practices. Please, follow the link to obtain instructions and code for those functions.
SCRIPT
'*********************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.
'*********************************************************************************
'Add Script Here
'you will need to pass it object that is the user, and the SMTP address that you will want to use.
'we use this inside an on "post modify" where it is looking to see if the first or last name was changed during the Quick Connect run.
Function changedefaultsmtp (objuser,newsmtp)
objuser.getinfo
newmail = ("SMTP:" & newsmtp) 'setting the email address that will be Default
For Each email In objuser.proxyAddresses 'looping through the proxies looking for anything we need to change before we set the Default
email2 = Left(email,5)
email3 = Ucase(email2) 'did this because Active Roles was having problems doing all this in one line.
If email3 = "SMTP:" Then
useremail = Mid(email, 6) 'this is the e-mail we are checking against
If ucase(useremail) = ucase(newsmtp) Then 'checking to make sure that the "newmail" doesn't already exist
objUser.PutEx ADS_PROPERTY_DELETE, "proxyAddresses", Array(email) 'delete that entry
objUser.SetInfo
Exit For 'dump out of the FOR next, we found that the user had this address already, and removed it, we will set it as default.
Else
If email2 = "SMTP:" Then 'if we find a default address then replace it with a regular address
objUser.PutEx ADS_PROPERTY_DELETE, "proxyAddresses", Array(email)
objUser.SetInfo
objuser.Getinfo
objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses", Array(lcase(email))
objUser.SetInfo
End If
End If
End If
Next
'setting new address as Default
objuser.Getinfo
objUser.put "mail",newsmtp
objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses", Array(newmail)
On Error Resume Next 'doing this so that we can see if there is an error so we can trap it and return it from the fuction.
objUser.SetInfo
If Err.Number <> 0 Then
changedefaultsmtp = Err.Description
Err.Clear
Else
changedefaultsmtp = "SUCCESS"
End If
'On Error GoTo 0 'probably should be removed since other parts of the script may rely on it.
End Function
'***** END OF CODE ***************************************************************