Changing username/mailbox

Discussion for developers using MailEnable.

Changing username/mailbox

Postby tomas.chovanec » Tue Jan 04, 2011 7:37 am

Hello,
I wonder to know if is possible to change username and mailbox name by MailEnable API .NET without loosing emails.
If I edit mailbox and username, there are no email in changed mailbox.
Code: Select all
            MailEnable.Administration.Mailbox mbox = new MailEnable.Administration.Mailbox();
            mbox.MailboxName = tChangeLoginCurrentName.Text;
            mbox.Postoffice = tChangeLoginPostOffice.Text;

            if (mbox.GetMailbox() == 1)
            {
                int returnValue = mbox.EditMailbox(
                    mbox.Postoffice,
                    tChangeLoginNewName.Text,
                    mbox.RedirectAddress,
                    mbox.RedirectStatus,
                    mbox.Status,
                    mbox.GetQuota(),
                    mbox.GetSize());

                if (returnValue == 1)
                {
                    MessageBox.Show("OK");
                }
                else
                {
                    MessageBox.Show("ERROR!");
                }
            }
            else
            {
                MessageBox.Show("ERROR!");
            }

            MailEnable.Administration.Login lo = new MailEnable.Administration.Login();
            lo.UserName = tChangeLoginCurrentName.Text + "@" + tChangeLoginPostOffice.Text;
            lo.Account = tChangeLoginPostOffice.Text; // Postoffice
            lo.Description = "";
            lo.Password = "";
            lo.Rights = "";
            lo.Status = 1;

            if (lo.GetLogin() == 1)
            {
                int editLoginStatus = lo.EditLogin(tChangeLoginNewName.Text + "@" + tChangeLoginPostOffice.Text, lo.Status, lo.Password, lo.Account, lo.Description, -1, -1, -1, string.IsNullOrWhiteSpace(lo.Rights) ? "USER" : lo.Rights);
                if (editLoginStatus == 1)
                    MessageBox.Show("OK");
                else
                    MessageBox.Show("ERROR!");
            }
            else
            {
                MessageBox.Show("ERROR!");
            }

            MailEnable.Administration.AddressMap am = new MailEnable.Administration.AddressMap();
            am.Account = tChangeLoginNewName.Text;
            am.DestinationAddress = string.Format("[SF:{0}/{1}]", tChangeLoginPostOffice.Text, tChangeLoginNewName.Text);
            am.Scope = "";
            am.SourceAddress = string.Format("[SMTP:{0}@{1}]", tChangeLoginNewName.Text, tChangeLoginPostOffice.Text);
            int addressMapAdded = am.AddAddressMap();
tomas.chovanec
 
Posts: 8
Joined: Tue Oct 26, 2010 12:11 pm

Re: Changing username/mailbox

Postby MailEnable » Tue Jan 04, 2011 10:27 am

To rename a mailbox you would need to do the following.

1. Edit the Login and rename it to NewMailboxName@Postoffice
2. Edit the Mailbox and rename the MailboxName
3. Find All AddressMaps for the Mailbox and map to the new mailbox
4. Access the File System and Rename the MailboxName.Sys File Under the Config/Postoffices/Mailbox directory
5. Access the File System and Rename the Postoffices/Postoffice/MailBox to have the new mailbox name - since this will place all the emails into the location of the new mailbox.
Regards, Andrew
MailEnable
Site Admin
 
Posts: 4424
Joined: Tue Jun 25, 2002 3:03 am
Location: Melbourne, Victoria Australia

Re: Changing username/mailbox

Postby tomas.chovanec » Tue Jan 04, 2011 11:58 am

Thank you
tomas.chovanec
 
Posts: 8
Joined: Tue Oct 26, 2010 12:11 pm

Re: Changing username/mailbox

Postby MailEnable » Tue Jan 04, 2011 1:41 pm

You're welcome. Also... there is a utility that does all that for you if you wish:
http://www.mailenable.com/addons_Management.asp

The source for the Rename Mailbox utility is available (as VB 6) here: http://www.mailenable.com/developers/Re ... Source.zip

Plus, if you want examples for using the API, the ClassicASP source is available from the developers download page.
Regards, Andrew
MailEnable
Site Admin
 
Posts: 4424
Joined: Tue Jun 25, 2002 3:03 am
Location: Melbourne, Victoria Australia


Return to MailEnable Developers

Who is online

Users browsing this forum: No registered users and 0 guests