Help! How to rename a post office and update users/groups

Discussion for developers using MailEnable.
Post Reply
CWIMike
Posts: 18
Joined: Tue Dec 31, 2002 8:57 pm

Help! How to rename a post office and update users/groups

Post by CWIMike »

I'm trying to rename a post office to a different name in order to change its domain name, using the API, but can't get any users or groups to move.

I'm just trying to move groups at all, and groups either disappear from view, or won't move, staying in the first domain and not moving to the second.

Here's my function - varAccount is the old domain, varDomain is the new one.

Code: Select all

Function Mail_RenameDomain(varAccount, varDomain)
	' Create new post office to hold the new stuff and add the new domains to it
	Set oPostOffice = Server.CreateObject("MEAOPO.PostOffice")
	oPostOffice.Name = varDomain
	oPostOffice.Status = 1
	oPostOffice.Account = varDomain
	varResult = oPostOffice.AddPostOffice()

	if varResult = 0 then
		Mail_RenameDomain = 1
		Exit Function
	end if
	
	varResult = Mail_AddDomain(varDomain, varDomain)
	
	if varResult = 0 then
		Mail_RenameDomain = 2
		Exit Function
	end if
	
	' Move over all the domains except those named the same as {varAccount}
	
	Set oDomain = Server.CreateObject("MEAOSM.Domain")
	oDomain.DomainName = ""
	oDomain.Status = -1
	oDomain.DomainRedirectionStatus = -1
	oDomain.DomainRedirectionHosts = ""
	oDomain.AccountName = varAccount
	varResult = oDomain.FindFirstDomain()
	if varResult <> 0 then
		Do
			varResult = oDomain.EditDomain(oDomain.DomainName, oDomain.Status, oDomain.DomainRedirectionStatus, oDomain.DomainRedirectionHosts, varDomain)
			if varResult = 0 then 
				Mail_RenameDomain = 3
				Exit Function
			end if
			oDomain.DomainName = ""
			oDomain.Status = -1
			oDomain.DomainRedirectionStatus = -1
			oDomain.DomainRedirectionHosts = ""
			oDomain.AccountName = varAccount
		Loop While oDomain.FindFirstDomain() = 1
	end if

	Set oGroup = Server.CreateObject("MEAOPO.Group")
	oGroup.RecipientAddress = ""
	oGroup.PostOffice = varAccount
	oGroup.GroupName = ""
	oGroup.GroupFile = ""
	oGroup.GroupStatus = -1
	varResult = oGroup.FindFirstGroup()
	if varResult <> 0 then
'		Do
			OldAddy = oGroup.RecipientAddress
			OldAddy = Replace(OldAddy, "SF:" & varAccount, "SF:" & varDomain)
			varResult = oGroup.EditGroup(OldAddy, varDomain, oGroup.GroupName, oGroup.GroupFile, oGroup.GroupStatus)
			Response.Write varResult
			if varResult = 0 then 
				Mail_RenameDomain = 4
				Exit Function
			end if
			oGroup.RecipientAddress = ""
			oGroup.PostOffice = varAccount
			oGroup.GroupName = ""
			oGroup.GroupFile = ""
			oGroup.GroupStatus = -1
'		loop while oGroup.FindFirstGroup() = 1
	end if
	
	Set oAddressMap = Server.CreateObject("MEAOAM.AddressMap")
	oAddressMap.SourceAddress = ""
	oAddressMap.DestinationAddress = ""
	oAddressMap.Scope = ""
	oAddressMap.Account = varAccount
	varResult = oAddressMap.FindFirstAddressMap()
	
	if varResult <> 0 then
'		Do
			OldAddyD = oAddressMap.DestinationAddress
			OldAddyD = Replace(OldAddyD, "SF:" & varAccount, "SF:" & varDomain)
			OldAddyD = Replace(OldAddyD, "SF:mail." & varAccount, "SF:mail." & varDomain)
			OldAddyS = oAddressMap.SourceAddress
			OldAddyS = Replace(OldAddyS, "@" & varAccount, "@" & varDomain)
			OldAddyS = Replace(OldAddyS, "@mail." & varAccount, "@mail." & varDomain)

			varResult = oAddressMap.EditAddressMap(varDomain, OldAddyS, OldAddyD, oAddressMap.Scope)
			if varResult = 0 then 
				Mail_RenameDomain = 5
				Exit Function
			end if
			oAddressMap.SourceAddress = ""
			oAddressMap.DestinationAddress = ""
			oAddressMap.Scope = ""
			oAddressMap.Account = varAccount
'		loop while oAddressMap.FindFirstAddressMap() = 1
	end if
	
	Mail_RenameDomain = True
End Function
Help!

Admin
Site Admin
Posts: 1127
Joined: Mon Jun 10, 2002 6:31 pm
Location: Melbourne, Victoria, Australia

Post by Admin »

We've put a post office renaming tool up on our download page (under Unsupported area). It includes source code in Visual Basic 6, but should be an easy matter to script it.

You need to change quite a few files (authentication, address-map, domain, postoffice and group files). Also, if Professional is installed, you need to change the POP Retrieval config.

To alter details with a group, use FindFirst/FindNext. Since the actual file doesn't contain the post office name, doing FindFirst will always return the first item if you have multiple groups.

After doing all the file modifications through the administration objects you still need to change the directory names for the post office configuration and data directories.

Post Reply