Script to change email addresses of outlook contacts
Exchange 2007 environment. Every mailbox has their own local copy of contacts.
I just changed our domain in order to shorten it, and instead of having users go in and change each one of their local contacts, I'd like to write a script that iterates through each of their local contacts, and if the email address ends with '@oldemailaddress.com' I'd like t开发者_JS百科o change it to '@newaddy.com'.
It would also be nice if the same script would open their .n2k file and edit those addresses as well.
Is this possible? Would it be a script for each client or would it be a script or cmd I could run on my Exchange 2007 server (sans the n2k)?
Thanks!
I think I found the solution on my own.
Const olFolderContacts = 10
sOldDomain = "@olddomain.com"
sNewDomain = "@newdomain.com"
Set oOutlook = CreateObject("Outlook.Application")
Set oNamespace = oOutlook.GetNamespace("MAPI")
Set oContactFolder = oNamespace.GetDefaultFolder(olFolderContacts)
For Each item in oContactFolder.Items
If InStr(1, item.Email1Address, sOldDomain, vbTextCompare) > 0 Then _
item.Email1Address = Replace(item.Email1Address, sOldDomain, sNewDomain, 1, 1, vbTextCompare)
If InStr(1, item.Email2Address, sOldDomain, vbTextCompare) > 0 Then _
item.Email2Address = Replace(item.Email2Address, sOldDomain, sNewDomain, 1, 1, vbTextCompare)
If InStr(1, item.Email3Address, sOldDomain, vbTextCompare) > 0 Then _
item.Email3Address = Replace(item.Email3Address, sOldDomain, sNewDomain, 1, 1, vbTextCompare)
item.Save
Next
Wscript.Echo "Finished."
精彩评论